梯度下降法-python代码
2011-10-30 12:56
183 查看
一个通过迭代求解convex function最小值的方法: Gradient descent(梯度下降法)
http://en.wikipedia.org/wiki/Gradient_descent
这里给出一个python的代码:
The gradient descent algorithm is applied to find a local minimum of the function f(x)=x4-3x3+2
, with derivative f'(x)=4x3-9x2.
Here is an implementation in the Python
programming language.
# From
calculation, we expect that the local minimum occurs at x=9/4
xOld = 0
xNew = 6 # The
algorithm starts at x=6
eps = 0.01 # step
size
precision = 0.00001
def f_prime(x):
return 4 * x**3 - 9 * x**2
while abs(xNew - xOld) > precision:
xOld = xNew
xNew = xOld - eps * f_prime(xNew)
print("Local
minimum occurs at ",
xNew)
http://en.wikipedia.org/wiki/Gradient_descent
这里给出一个python的代码:
The gradient descent algorithm is applied to find a local minimum of the function f(x)=x4-3x3+2
, with derivative f'(x)=4x3-9x2.
Here is an implementation in the Python
programming language.
# From
calculation, we expect that the local minimum occurs at x=9/4
xOld = 0
xNew = 6 # The
algorithm starts at x=6
eps = 0.01 # step
size
precision = 0.00001
def f_prime(x):
return 4 * x**3 - 9 * x**2
while abs(xNew - xOld) > precision:
xOld = xNew
xNew = xOld - eps * f_prime(xNew)
print("Local
minimum occurs at ",
xNew)
相关文章推荐
- 梯度下降法Python代码
- 梯度下降原理及线性回归代码实现(python/java/c++)
- Python神经网络代码实现流程(三):反向传播与梯度下降
- 梯度下降法与随机梯度下降法的python代码实现
- 梯度下降实现案例(含python代码)
- 线性回归之梯度下降法(附代码)
- Python实战二.梯度下降 多元回归
- 线性回归与梯度下降(gradient descent) python
- 线性回归的正规方程解法与梯度下降解法的代码
- 1、梯度下降c代码
- 梯度下降法及其Python实现
- [ 筆記 ] 用 Python 訓練一個神經元 (解決異或問題, 梯度下降法, Delta 學習規則)
- [机器学习]逻辑回归公式推导及其梯度下降法的Python实现
- 梯度下降的python实现
- 机器学习小组知识点4&5:批量梯度下降法(BGD)和随机梯度下降法(SGD)的代码实现Matlab版
- python利用梯度下降求多元线性回归
- 逻辑回归-梯度下降法 python实现
- 梯度下降法快速教程 | 第一章:Python简易实现以及对学习率的探讨
- 梯度下降法快速教程 | 第二章:冲量(momentum)的原理与Python实现
- 机器学习入门:线性回归及梯度下降(附matlab代码)