The component and implementation of a basic gradient descent in python
in my impression, the gradient descent is for finding the independent variable that can get the minimum/maximum value of an objective function. So we need an obj. function: \(\mathcal{L}\)
- an obj. function: \(\mathcal{L}\)
- The gradient of \(\mathcal{L}: 2x+2\)
- \(\Delta x\) , The value of idependent variable needs to be updated: \(x \leftarrow x+\Delta x\)
1. the \(\mathcal{L}\) is a context function: \(f(x)=x^2+2x+1\)
how to find the \(x_0\) that makes the \(f(x)\) has the minimum value, via gradient descent?
Start with an arbitrary \(x\), calculate the value of \(f(x)\) :
import random
def func(x):
return x*x + 2*x +1
def gred(x): # the gradient of f(x)
return 2*x + 2
x = random.uniform(-10.0,10.0) #randomly pick a float in interval of (-10, 10)
# x = 10
print('x starts at:', x)
y0 = func(x) #first cal
delta = 0.5 #the value of delta_x, each iteration
x = x + delta
# === interation ===
for i in range(100):
print('i=',i)
y1 = func(x)
delta = -0.08*gred(x)
print(' delta=',delta)
if y1 > y0:
print(' y1>y0')
# if gred(x) is positive, the x should decrease.
# if gred(x) is negative, the x should increase.
else:
print(' y1<=y0')
# if gred(x) is positive, the x should increase.
# if gred(x) is negative, the x should decrease.
x = x+delta
y0 = y1
print(' x=', x, 'f(x)=', y1)
Let's disscuss how to determin the some_value in the psudo code above.
if \(y_1-y_0\) has a large positive difference, i.e. \(y1 >> y0\), the x should shift backward heavily. so the some_value can be a ratio of \((y_1-y_0)\times(-gradient)\) , Let's say, some_value: \(\lambda = r \times\) gred(x) , here, \(r=0.08\) is the step-size.
The basic gradient descent has many shortcomings which can be found by search the 'shortcoming of gd'.
Another problem of GD algorithm is , What if the \(\mathcal{L}\) does not have explicit expression of its gradient?
Stochastic Gradient Descent(SGD) is another GD algorithm.
The component and implementation of a basic gradient descent in python的更多相关文章
- (转)Introduction to Gradient Descent Algorithm (along with variants) in Machine Learning
Introduction Optimization is always the ultimate goal whether you are dealing with a real life probl ...
- Logistic Regression and Gradient Descent
Logistic Regression and Gradient Descent Logistic regression is an excellent tool to know for classi ...
- (转) An overview of gradient descent optimization algorithms
An overview of gradient descent optimization algorithms Table of contents: Gradient descent variants ...
- 机器学习-随机梯度下降(Stochastic gradient descent)
sklearn实战-乳腺癌细胞数据挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003& ...
- An overview of gradient descent optimization algorithms
原文地址:An overview of gradient descent optimization algorithms An overview of gradient descent optimiz ...
- 机器学习数学基础- gradient descent算法(上)
为什么要了解点数学基础 学习大数据分布式计算时多少会涉及到机器学习的算法,所以理解一些机器学习基础,有助于理解大数据分布式计算系统(比如spark)的设计.机器学习中一个常见的就是gradient d ...
- flink 批量梯度下降算法线性回归参数求解(Linear Regression with BGD(batch gradient descent) )
1.线性回归 假设线性函数如下: 假设我们有10个样本x1,y1),(x2,y2).....(x10,y10),求解目标就是根据多个样本求解theta0和theta1的最优值. 什么样的θ最好的呢?最 ...
- 梯度下降(Gradient Descent)小结
在求解机器学习算法的模型参数,即无约束优化问题时,梯度下降(Gradient Descent)是最常采用的方法之一,另一种常用的方法是最小二乘法.这里就对梯度下降法做一个完整的总结. 1. 梯度 在微 ...
- 机器学习基础——梯度下降法(Gradient Descent)
机器学习基础--梯度下降法(Gradient Descent) 看了coursea的机器学习课,知道了梯度下降法.一开始只是对其做了下简单的了解.随着内容的深入,发现梯度下降法在很多算法中都用的到,除 ...
随机推荐
- SQL Server中的连接查询(内连接、外连接、交叉连接)
在数据库查询中,经常会用到两个有关联的表进行查询,需要把两个表中的数据按照某些条件查出来,这时就可以使用连接查询 连接查询分为三种:内连接.外连接和交叉连接 1. 内连接 内连接inner join ...
- js中数组常用方法总结
操作数组 印象中数组有很多方法,系统的整理一下,放在自己家里方便回头查~ Array.map() 此方法是将数组中的每个元素调用一个提供的函数,结果作为一个新的数组返回,并没有改变原来的数组 1 2 ...
- vlookup使用
数据处理过程中,需要excel进行简单的操作,比如vlookup,摸索之后,总结如下:
- js 实现仿 淘宝 五星评价 demo
<style> @font-face { font-family: 'iconfont'; /* project id 247957 */ src: url('//at.alicdn.co ...
- 2018.5.4 Unix的五种IO模型
阻塞非阻塞和异步同步 同步和异步关注的是消息通信机制,关注两个对象之间的调用关系. 阻塞和非阻塞关注的是程序在等待调用结果(消息,返回值)时的状态,关注单一程序. Unix的五种IO模型 以下基于Li ...
- PY序
Python实现机器学习依赖于两个类库——SciPy和scikit-learn 一)SciPy SciPy是数学运算的基本类库,在机器学习的过程中,主要运用NumPy.Matplotlib和Panda ...
- Linux下RabbitMQ的安装 开机自启动
1.官网下载地址 下载 RabbitMQ 和 erlang.我下载的是rabbitmq-server-3.6.10-1.el7.noarch.rpm和erlang-19.0.4-1.el7.cento ...
- javascript 操作节点的属性
使用层次关系访问节点 parentNode:返回节点的父节点 childNodes:返回子节点集合,childNodes[i] firstChild:返回节点的第一个子节点,最普遍的用法是访问该元素的 ...
- EBS WEBADI导入日记账 客户化账户组合规则校验
近期项目需求对EBS中WEBADI导入日记账时,在加载数据时需要对账户组合额外进行客户化的校验,需要能够做到将校验结果体现在WEBADI模板的数据上,并且对每条错误数据都单独报错. 项目上的方案是调整 ...
- java web(二): servlet的简单使用和介绍
前言:通过编写一个servlet类,向浏览器发送hello world来阐述servlet. 一:创建动态web项目 1. 首先切换到javaEE视图. 在ecplise左边即项目管理器哪里右键点击新 ...