当前位置:网站首页>梯度下降法介绍-黑马程序员机器学习讲义
梯度下降法介绍-黑马程序员机器学习讲义
2022-06-24 03:55:00 【黑马程序员官方】
学习目标
- 知道全梯度下降算法的原理
- 知道随机梯度下降算法的原理
- 知道随机平均梯度下降算法的原理
- 知道小批量梯度下降算法的原理
上一节中给大家介绍了最基本的梯度下降法实现流程,常见的梯度下降算法有:
- 全梯度下降算法(Full gradient descent),
- 随机梯度下降算法(Stochastic gradient descent),
- 小批量梯度下降算法(Mini-batch gradient descent),
- 随机平均梯度下降算法(Stochastic average gradient descent)
它们都是为了正确地调节权重向量,通过为每个权重计算一个梯度,从而更新权值,使目标函数尽可能最小化。其差别在于样本的使用方式不同。
1 全梯度下降算法(FG)
计算训练集所有样本误差,对其求和再取平均值作为目标函数。
权重向量沿其梯度相反的方向移动,从而使当前目标函数减少得最多。
因为在执行每次更新时,我们需要在整个数据集上计算所有的梯度,所以批梯度下降法的速度会很慢,同时,批梯度下降法无法处理超出内存容量限制的数据集。
批梯度下降法同样也不能在线更新模型,即在运行的过程中,不能增加新的样本。
其是在整个训练数据集上计算损失函数关于参数θ的梯度:

2 随机梯度下降算法(SG)
由于FG每迭代更新一次权重都需要计算所有样本误差,而实际问题中经常有上亿的训练样本,故效率偏低,且容易陷入局部最优解,因此提出了随机梯度下降算法。
其每轮计算的目标函数不再是全体样本误差,而仅是单个样本误差,即每次只代入计算一个样本目标函数的梯度来更新权重,再取下一个样本重复此过程,直到损失函数值停止下降或损失函数值小于某个可以容忍的阈值。
此过程简单,高效,通常可以较好地避免更新迭代收敛到局部最优解。其迭代形式为

其中,x(i)表示一条训练样本的特征值,y(i)表示一条训练样本的标签值
但是由于,SG每次只使用一个样本迭代,若遇上噪声则容易陷入局部最优解。
3 小批量梯度下降算法(mini-batch)
小批量梯度下降算法是FG和SG的折中方案,在一定程度上兼顾了以上两种方法的优点。
每次从训练样本集上随机抽取一个小样本集,在抽出来的小样本集上采用FG迭代更新权重。
被抽出的小样本集所含样本点的个数称为batch_size,通常设置为2的幂次方,更有利于GPU加速处理。
特别的,若batch_size=1,则变成了SG;若batch_size=n,则变成了FG.其迭代形式为

4 随机平均梯度下降算法(SAG)
在SG方法中,虽然避开了运算成本大的问题,但对于大数据训练而言,SG效果常不尽如人意,因为每一轮梯度更新都完全与上一轮的数据和梯度无关。
随机平均梯度算法克服了这个问题,在内存中为每一个样本都维护一个旧的梯度,随机选择第i个样本来更新此样本的梯度,其他样本的梯度保持不变,然后求得所有梯度的平均值,进而更新了参数。
如此,每一轮更新仅需计算一个样本的梯度,计算成本等同于SG,但收敛速度快得多。
5 小结
- 全梯度下降算法(FG)【知道】
- 在进行计算的时候,计算所有样本的误差平均值,作为我的目标函数
- 随机梯度下降算法(SG)【知道】
- 每次只选择一个样本进行考核
- 小批量梯度下降算法(mini-batch)【知道】
- 选择一部分样本进行考核
- 随机平均梯度下降算法(SAG)【知道】
- 会给每个样本都维持一个平均值,后期计算的时候,参考这个平均值
边栏推荐
- Physicochemical properties and specificity of Worthington trypsin
- 2020年Android面试题汇总(初级)
- [new light weight first purchase special] 1-core 2g5m light weight application server costs 50 yuan in the first year. It is cost-effective and helps you get on the cloud easily!
- ARM 架构、ARM7、ARM9、STM32、Cortex M3 M4 、51、AVR 有啥区别
- Final summary of freshman semester (supplement knowledge loopholes)
- ribbon
- Easygbs video playback protocol only webrtc can play. Troubleshooting
- How to modify the channel name registered by the camera in the easygbs national standard platform?
- Abnova peptide design and synthesis solutions
- Jointly build Euler community and share Euler ecology | join hands with Kirin software to create a digital intelligence future
猜你喜欢

Abnova fluorescence in situ hybridization (FISH) probe solution

Opengauss version 3.0 source code compilation and installation guide

Idea创建Servlet 后访问报404问题

The results of the 2022 open source summer were announced, and 449 college students will contribute to open source projects

apipost接口断言详解

Apipost interface assertion details

外网访问svn服务器(外网访问部署在云上的svn服务器)

Introduction to C language custom types (structure, enumeration, union, bit segment)
Summary of Android interview questions in 2020 (intermediate)
2020年Android面试题汇总(中级)
随机推荐
Congratulations to Zhong Jun for becoming the maintainer of chaos metric model working group
event
How to monitor multiple platforms simultaneously when easydss/easygbs platform runs real-time monitoring?
抢先报名丨新一代 HTAP 数据库如何在云上重塑?TiDB V6 线上发布会即将揭晓!
Doctor application | Hong Kong University of science and Technology (Guangzhou) Mr. Liu Hao recruits the full award doctor / Master in data mining
Apipost interface assertion details
web渗透测试----5、暴力破解漏洞--(6)VNC密码破解
An interface testing software that supports offline document sharing in the Intranet
Specificity and correlation of Worthington deoxyribonuclease I
How to set the domain name on the server what is the role of the domain name
Diskpart San policy is not onlineall, which affects automatic disk hanging
Advanced authentication of uni app [Day12]
mysql - sql执行过程
Database answers build standard, answer as required
How to identify information more quickly and accurately through real-time streaming media video monitoring?
ribbon
How to adjust the alarm information that remains unchanged after paging is selected on the easygbs alarm page?
图书馆管理后台
[receive] new benefits of 60 yuan / year? Lowest in history! Double 11 has now begun to seize resources! Get started quickly!!
Why is on-line monitoring of equipment more and more valued by people?