2

[ML Notes] 拉格朗日函数:直观解释

 3 years ago
source link: https://blog.nex3z.com/2021/03/14/ml-notes-%e6%8b%89%e6%a0%bc%e6%9c%97%e6%97%a5%e5%87%bd%e6%95%b0-%e7%9b%b4%e8%a7%82%e8%a7%a3%e9%87%8a/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

[ML Notes] 拉格朗日函数:直观解释

Author: nex3z 2021-03-14

  以二元函数为例,要寻找 f(x,y) 在约束条件 g(x,y)=0 下的极值,如

minf(x,y)s.t.g(x,y)=0

  假设 f(x,y) 在 (x0,y0) 处取得极值 z,则在该处,f(x,y)=z 和 g(x,y)=0 两条曲线应相切,两条曲线在 (x0,y0) 处的梯度应平行。于是得到方程组

{∇f+λ∇g=0g(x,y)=0

由此可以解出 x、y 和 λ,(x,y) 即为函数 f(x,y) 在附加条件 g(x,y)=0 下的可能的极值点。

  举例来说,令

f(x,y)=–x–y2+y+3g(x,y)=2∗x+y–1

优化问题为

min–x–y2+y+3s.t.2∗x+y–1=0

如图 1 所示,等高线为 f(x,y),黑色直线为 g(x,y),在 f(x,y) 和 g(x,y) 相切处(红点),f(x,y) 取得极值,且二者的梯度方向相同。

图 1图 1

  计算 f(x,y) 和 g(x,y) 的梯度为

∇f=[−1−2y+1]∇g=[21]

由式 (2),得到方程组

{[−1−2y+1]+λ[21]=02x+y–1=0

解得 x=0.125,y=0.75,λ=0.5,极值为 f(0.375,0.25)=3.5625。∇f∇g=−λ=−0.5,说明 f 和 g 的梯度方向相反,前者长度为后者的一半。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK