matlab中ridge和A\b的区别
给定相同的 A
、b
和 L2 正则化参数 beta = 0
,为什么 ridge
和 \给出两种不同的解决方案?
b = [ 0
-2
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3 ];
A = [
1 0 0 0
0.750000000000000 0.250000000000000 0 0
0.500000000000000 0.500000000000000 0 0
0.250000000000000 0.750000000000000 0 0
0 1 0 0
0 0.750000000000000 0.250000000000000 0
0 0.500000000000000 0.500000000000000 0
0 0.250000000000000 0.750000000000000 0
0 0 1 0
0 0 0.750000000000000 0.250000000000000
0 0 0.500000000000000 0.500000000000000
0 0 0.250000000000000 0.750000000000000
0 0 0 1
];
>> ridge(b, A, 0,0)
ans =
0.6942
-0.1856
0
-0.0468
>> A \ b
ans =
-0.8604
-3.4188
-2.8970
-3.0343
Given the same A
, b
and L2 regularization parameter beta = 0
, why do ridge
and \
give two different solutions?
b = [ 0
-2
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3
-3 ];
A = [
1 0 0 0
0.750000000000000 0.250000000000000 0 0
0.500000000000000 0.500000000000000 0 0
0.250000000000000 0.750000000000000 0 0
0 1 0 0
0 0.750000000000000 0.250000000000000 0
0 0.500000000000000 0.500000000000000 0
0 0.250000000000000 0.750000000000000 0
0 0 1 0
0 0 0.750000000000000 0.250000000000000
0 0 0.500000000000000 0.500000000000000
0 0 0.250000000000000 0.750000000000000
0 0 0 1
];
>> ridge(b, A, 0,0)
ans =
0.6942
-0.1856
0
-0.0468
>> A \ b
ans =
-0.8604
-3.4188
-2.8970
-3.0343
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为,正如您在 文档 中看到的,
ridge
使用的算法与mldivide
略有不同:因为“经典”伪逆 ((A' *A)^-1 * A)可能会变成对于接近奇异值的 (A' *A)^-1 的小误差敏感,公式修改为 (A' *< em>A - kI)^-1 *A,减少问题的条件。That's because, as you can se in the documentation,
ridge
uses a slightly different algorithm thanmldivide
: since the "classical" pseudoinverse ((A' *A)^-1 *A) could become sensible to small errors for (A' *A)^-1 close to singular values, the formula is modified to (A' *A - kI)^-1 *A, reducing the conditioning of the problem.