LASSO近端梯度下降法Proximal Gradient Descent公式推导及代码

LASSO by Proximal Gradient Descent

Prepare:
准备:

from itertools import cycle
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import lasso_path, enet_path
from sklearn import datasets
from copy import deepcopy

X = np.random.randn(100,10)
y = np.dot(X,[1,2,3,4,5,6,7,8,9,10])

Proximal Gradient Descent Framework近端梯度下降算法框架

  1. randomly set β ( 0 ) \beta^{(0)} β(0) for iteration 0
  2. For k k kth iteration:
    ----Compute gradient ∇ f ( β ( k − 1 ) ) \nabla f(\beta^{(k-1)}) f(β(k1))
    ----Set z = β ( k − 1 ) − 1 L ∇ f ( β ( k − 1 ) ) z = \beta^{(k-1)} - \frac{1}{L} \nabla f(\beta^{(k-1)}) z=β(k1)L1f(β(k1))
    ----Update β ( k ) = sgn ( z ) ⋅ max [ ∣ z ∣ − λ L ,    0 ] \beta^{(k)} = \text{sgn}(z)\cdot \text{max}[|z|-\frac{\lambda}{L}, \; 0] β(k)=sgn(z)max[zLλ,0]
    ----Check convergence: if yes, end algorithm; else continue update
    Endfor

Here f ( β ) = 1 2 N ( Y − X β ) T ( Y − X β ) f(\beta) = \frac{1}{2N}(Y-X\beta)^T (Y-X\beta) f(β)=2N1(YXβ)T(YXβ), and ∇ f ( β ) = − 1 N X T ( Y − X β ) \nabla f(\beta) = -\frac{1}{N}X^T(Y-X\beta) f(β)=N1XT(YXβ),
where the size of X X X, Y Y Y, β \beta β is N × p N\times p N×p, N × 1 N\times 1 N×1, p × 1 p\times 1 p×1, which means N N N samples样本 and p p p features特征. Parameter L ≥ 1 L \ge 1 L1 can be chosen, and 1 L \frac{1}{L} L1 can be considered as step size步长.

Proximal Gradient Descent Details近端梯度下降细节推导

Consider optimization problem:
现考虑优化问题:
min x f ( x ) + λ ⋅ g ( x ) , \text{min}_x {f(x) + \lambda \cdot g(x)}, minxf(x)+λg(x),
where x ∈ R p × 1 x\in \mathbb{R}^{p\times 1} xRp×1, f ( x ) ∈ R f(x) \in \mathbb{R} f(x)R. And f ( x ) f(x) f(x) is differentiable convex function, and g ( x ) g(x) g(x) is convex but may not differentiable.
f ( x ) f(x) f(x)是可微凸函数, g ( x ) g(x) g(x)是凸函数但不一定可微。

For f ( x ) f(x) f(x), according to Lipschitz continuity, for ∀ x , y \forall x, y x,y, there always exists a constant L L L s.t.
对于 f ( x ) f(x) f(x),根据利普希茨连续性,对于任意 x , y x,y x,y,一定存在常数 L L L使得满足
∣ f ′ ( y ) − f ′ ( x ) ∣ ≤ L ∣ y − x ∣ . |f'(y) - f'(x)| \le L|y-x|. f(y)f(x)Lyx.
Then this problem can be solved using Proximal Gradient Descent.
可以用近似梯度下降来解决这种问题。

Denote x ( k ) x^{(k)} x(k) as the k k kth updated result for x x x, then for x → x ( k ) x\to x^{(k)} x

### 近端梯度下降法 (Proximal Gradient Descent) 的概念 近端梯度下降法是一种用于求解带有非光滑正则化项的目标函数优化问题的方法。传统梯度下降方法仅适用于目标函数完全可微的情况,而当目标函数包含非光滑部分时,则难以直接应用。通过引入近端算子(Proximal Operator),该方法能够有效应对这一挑战[^2]。 核心思想在于将目标函数分解为两部分:平滑部分 \( g(x) \) 和非光滑部分 \( h(x) \)[^3]。对于这样的复合结构,更新规则可以表示为: \[ x^{k+1} = \text{argmin}_u \left\{\frac{1}{2t}\|u - (x^k - t\nabla g(x^k))\|^2_2 + h(u)\right\} \] 其中 \( t \) 是步长参数,通常可以通过线搜索或者固定值设定[^3]。 --- ### Python 实现代码 以下是基于上述理论的一个简单实现版本,假设目标是最小化如下形式的函数: \[ f(x) = g(x) + h(x) \] 其中 \( g(x) \) 表示平滑凸函数,\( h(x) \) 表示非光滑凸函数。具体实现如下所示: ```python import numpy as np def prox_l1(v, gamma): """L1 范数对应的近端映射""" return np.sign(v) * np.maximum(np.abs(v) - gamma, 0) def gradient_g(x): """计算平滑部分 g(x) 的梯度""" # 假设 g(x) = ||Ax-b||^2 / 2 A = np.array([[1, 2], [3, 4]]) b = np.array([1, 2]) grad = A.T @ (A @ x - b) return grad def proximal_gradient_descent(g_grad_func, prox_h_func, initial_x, step_size, max_iter=1000, tol=1e-6): """ Proximal Gradient Descent 算法实现 参数: g_grad_func: 平滑部分 g(x) 的梯度函数 prox_h_func: 非光滑部分 h(x) 对应的近端映射函数 initial_x: 初始点 step_size: 步长 max_iter: 最大迭代次数 tol: 收敛容忍度 返回: optimal_x: 最优解 """ x = initial_x.copy() for _ in range(max_iter): grad_g = g_grad_func(x) y = x - step_size * grad_g new_x = prox_h_func(y, step_size) if np.linalg.norm(new_x - x) < tol: break x = new_x return x # 初始化变量并运行算法 initial_point = np.array([0.0, 0.0]) step_length = 0.1 optimal_solution = proximal_gradient_descent( gradient_g, lambda v, gamma: prox_l1(v, gamma), initial_point, step_length ) print("Optimal solution:", optimal_solution) ``` --- ### 应用场景 近端梯度下降法广泛应用于各种实际领域中的稀疏优化问题,例如但不限于以下几种情况: #### 1. **压缩感知** 在信号恢复过程中,利用 L1 范数作为惩罚项来促进稀疏性解决方案。此时,目标函数的形式可能为: \[ f(x) = \|Ax - b\|_2^2 + \lambda \|x\|_1 \] 这里 \( \|x\|_1 \) 即为非光滑部分,可通过近端梯度下降法高效求解[^4]。 #### 2. **图像去噪** 采用总变差(Total Variation, TV)模型进行图像降噪时,TV 范数是非光滑项的一部分,因此适合使用此类技术处理。 #### 3. **机器学习中的特征选择** 在线性回归或其他监督学习任务中加入 Lasso 或 Group Lasso 类型约束条件时,同样需要用到这种方法寻找最佳权重向量。 ---
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值