Coursera | Andrew Ng (02-week-2-2.5)— 指数加权平均的偏差修正

该系列仅在原课程基础上部分知识点添加个人学习笔记,或相关推导补充等。如有错误,还请批评指教。在学习了 Andrew Ng 课程的基础上,为了更方便的查阅复习,将其整理成文字。因本人一直在学习英语,所以该系列以英文为主,同时也建议读者以英文为主,中文辅助,以便后期进阶时,为学习相关领域的学术论文做铺垫。- ZJ

Coursera 课程 |deeplearning.ai |网易云课堂


转载请注明作者和出处:ZJ 微信公众号-「SelfImprovementLab」

知乎https://zhuanlan.zhihu.com/c_147249273

****http://blog.****.net/JUNJUN_ZHAO/article/details/79099040


2.5 Bias correction in Exponentially weighted averages (指数加权平均的偏差修正)

(字幕来源:网易云课堂)

Coursera | Andrew Ng (02-week-2-2.5)— 指数加权平均的偏差修正

You’ve learned how to implement exponentially weighted averages.There’s one technical detail called bias correction that can make you computation of these averages more accurately.Let’s see how that works.In a previous video, you saw this figure for beta = 0.9.This figure for beta = 0.98.But it turns out that if you implement the formula as written here,you won’t actually get the green curve when, say, beta = 0.98.You actually get the purple curve here.And you notice that the purple curve starts off really low.So let’s see how to fix that.When you’re implementing a moving average,you initialize it with v0 = 0,and then v1 = 0.98 V0 + 0.02 data 1.But V0 is equal to 0 so that term just goes away.So V1 is just 0.02 times data 1.So that’s why if the first day’s temperature is, say 40 degrees Fahrenheit,then v1 will be 0.02 times 40, which is 8.So you get a much lower value down here.

Coursera | Andrew Ng (02-week-2-2.5)— 指数加权平均的偏差修正

你学过了如何计算指数加权平均数,有一个技术名词叫做偏差修正,可以让平均数运算更加准确,来看看它是怎么运作的,在上个视频中这个曲线对应 β 的值为 0.9,这个曲线对应的 β = 0.98,如果你执行写在这里的公式,在 β 等于 0.98 的时候 得到的并不是绿色曲线,而是紫色曲线,你可以注意到紫色曲线的起点较低,我们来看看怎么处理,计算移动平均数的时候,初始化v0 = 0,v1 = 0.98 * v0 + 0.02 乘以1号数据,但是v0 = 0 所以这部分没有了,所以v1等于 0.02 乘以 1 号数据,所以如果第一天温度是 40 华氏度,那么v1就是 0.02 乘以 40 也就是 8,因此得到的值会小很多,所以第一天温度的估测不准。

So it’s not a very good estimate of the first day’s temperature.v2 will be 0.98 times v1 + 0.02 times data 2.And if you plug in v1, which is this down here and multiply it out,then you find that v2 is actually equal to 0.98 times 0.02 times data 1plus 0.02 times data 2.And that 0.0 196 data1 + 0.02 data2.So again, assuming data1 and data2 are positive numbers,when you compute this v2 will be much less than data1 or data2.So v2 isn’t a very good estimate of the first two days’ temperature of the year.So it turns out that there is a way to modify this estimate that makes it much better, that makes it more accurate,especially during this initial phase of your estimate.

Coursera | Andrew Ng (02-week-2-2.5)— 指数加权平均的偏差修正

v2等于 0.98 乘以v1加上 0.02 乘以 2 号数据,如果代入v1 然后相乘,所以v2 = 0.98 * 0.02 乘以1号数据,加上 0.02 乘上2号数据,也就是 0.0196 乘以 1 号数据加上 0.02 乘上 2 号数据,假设 1 号和 2 号数据都是正数,计算后 v2要远小于 1 号和 2 号数据,所以v2不能很好估测出这一年前两天的温度有个办法可以修改这一估测,让估测变得更好 更准确,特别是在估测初期

Which is that, instead of taking vt, take vt divided by 1-Beta to the power of t where t is the current day you’re on.So let’s take a concrete example.When t = 2, 1- beta to the power of t is1- 0.98 squaredand it urns out that this is 0.0396.And so your estimate of the temperature on day 2becomes v2 divided by 0.0396 andthis is going to be 0.0196 times data 1 + 0.02 data 2.You notice that these two things adds up to the denominator 0.0396.And so this becomes a weighted average of data 1 and data 2,and this removes this bias.So you notice that as t becomes large,beta to the t will approach 0which is why when t is large enough,the bias correction makes almost no difference.This is why when t is large,the purple line and the green, line they are much over that.But during this initial phase of learning when you’re still warming up your estimates when the bias correction can help you to obtain a better estimate of this temperature.And it is this bias correction that helps yougo from the purple line to the green line.

Coursera | Andrew Ng (02-week-2-2.5)— 指数加权平均的偏差修正

也就是不用vt 而是用vt除以(1βt),t 就是现在的天数,举个具体例子,当 t = 2 时 1βt,也就是 10.982,答案是0.0396,因此对第二天温度的估测,变成了v2除以 0.0396,也就是 0.0196 乘以 1 号数据加上 0.02 乘以 2 号数据,然后二者相加 分母为 0.0396,这也就是 1 号和 2 号数据的加权平均数,并去除了偏差,你会发现随着 t 增加,β 的 t 次方将接近于 0,所以当 t 很大的时候,偏差修正几乎没有作用,因此当t较大的时候,紫线基本和绿线重合了。不过在开始学习阶段,你才开始预测热身练习,偏差修正可以帮助你更好预测温度,偏差修正可以帮助你,使结果从紫线变成绿线。

So in machine learning,for most implementations of the exponential weighted average,people don’t often bother to implement bias corrections.Because most people would rather just wait that initial period and have a slightly more biased estimate and go from there.But if you are concerned about the bias during this initial phase,while your exponentially weighted moving average is still warming up.Then bias correction can help you get a better estimate early on.So you now know how to implement exponentially weighted moving averages.Let’s go on and use this to build some better optimization algorithms.

在机器学习中,在计算指数加权平均数的大部分时候,大家不在乎执行偏差修正,因为大部分人宁愿熬过初始时期,拿到具有偏差的估测 然后继续计算下去,如果你关心初始时期的偏差,在刚开始计算指数加权移动平均数的时候,偏差修正能帮助你在早期获得更好的估测,所以你学会了计算指数加权移动平均数,我们接着就用它来构建更好的优化算法吧!


重点总结:

指数加权平均的偏差修正

在我们执行指数加权平均的公式时,当 β=0.98 时,我们得到的并不是图中的绿色曲线,而是下图中的紫色曲线,其起点比较低。

Coursera | Andrew Ng (02-week-2-2.5)— 指数加权平均的偏差修正

  • 原因:

v0=0v1=0.98v0+0.02θ1=0.02θ1v2=0.98v1+0.02θ2=0.98×0.02θ1+0.02θ2=0.0196θ1+0.02θ2

如果第一天的值为如40,则得到的 v1=0.02×40=8,则得到的值要远小于实际值,后面几天的情况也会由于初值引起的影响,均低于实际均值。

  • 偏差修正:

使用:vt1βt

当 t=2 时:

1βt=1(0.98)2=0.0396

v20.0396=0.0196θ1+0.02θ20.0396

偏差修正得到了绿色的曲线,在开始的时候,能够得到比紫色曲线更好的计算平均的效果。随着 t 逐渐增大,βt接近于 0,所以后面绿色的曲线和紫色的曲线逐渐重合了。

虽然存在这种问题,但是在实际过程中,一般会忽略前期均值偏差的影响。

参考文献:

[1]. 大树先生.吴恩达Coursera深度学习课程 DeepLearning.ai 提炼笔记(2-2)– 优化算法


PS: 欢迎扫码关注公众号:「SelfImprovementLab」!专注「深度学习」,「机器学习」,「人工智能」。以及 「早起」,「阅读」,「运动」,「英语 」「其他」不定期建群 打卡互助活动。

Coursera | Andrew Ng (02-week-2-2.5)— 指数加权平均的偏差修正