当前位置:网站首页>机器学习深度学习——向量化
机器学习深度学习——向量化
2022-06-25 04:00:00 【头发没了还会再长】
向量化
Whenever possible, avoid explicit for-loops.
为什么向量化
加快运算速率,这就要使用一个强大的工具包numpy
直接上代码看看非向量化和向量化的对比 计算 两个向量内积,可以看到,向量化的结果比非向量化的快了有三百倍
向量化的更多例子
矩阵和一个向量相乘
计算向量的指数运算
将向量化运用到logistic回归中
非向量化logistic回归的梯度下降代码:
在这个代码里面 有两个循环,绿色指示的部分,在计算dw的时候,如果我们有多个特征值,就要计算多个dw,此时n=2,dw就计算两个,很多的时候就要用循环解决,但是为了不循环,将下面的代码改成向量
将dw1,dw2 …改成一个向量dw表示,初始化dw为n_x行1列的0即可
向量化logistic回归
在上面的向量化中,简化了中间求dw的循环,这里,将for i=1 to m也简化掉,进行向量化
具体的做法是:
首先要求出z1,z2等,由z = wTx + b可知,应先将w,x和b向量化,x是输入的特征值个数,记为nx,而每一个样本都对应不同的输入,一共m个样本,所以有m列,所以x是R(nx,m)的矩阵,而w在上面已经知道是个R(nx,1)的矩阵,w*x得到的矩阵是R(1*m)的,所以b也是R(1*m)的,最后z = np.dot(w.t, X) + b
然后要计算a1,a2等,a是由一个激活函数对z求得的,当z已经求出,可以直接将向量放入激活函数求出向量a, 最后A = σ(Z)
向量化logistic回归的梯度输出
接下来就是计算dz,db,dw
最后,将向量化运用到logistic回归的梯度输出中去
边栏推荐
- Smart contract learning materials
- Value transfer between parent and child components of wechat applet
- Thorough understanding of database transactions
- Laravel document sorting 3. CSRF protection
- Comparison of towe/ JIRA / tapd / Zen collaboration platforms
- 【esp32学习之路6——flash加密】
- 升级cmake
- Detailed explanation of flex attributes in flex layout
- Should I use on or where for the left join
- Intel 13th generation core showed its true colors for the first time: 68mb cache improved significantly
猜你喜欢

CTF_ Web: deserialization of learning notes (II) CTF classic test questions from shallow to deep

mongodb集群

A detailed summary of four handshakes (or four waves) over TCP connections
![LeetCode 劍指Offer II 091 粉刷房子[動態規劃] HERODING的LeetCode之路](/img/ad/69fce7cf064479a0ddd477fb935de2.png)
LeetCode 劍指Offer II 091 粉刷房子[動態規劃] HERODING的LeetCode之路

CTF_ Web: Advanced questions of attack and defense world expert zone WP (19-21)

i. Max development board learning record

马斯克发布人形机器人,AI对马斯克为什么意义重大?

Summary of various problems encountered by cocos2d-x

Anaconda安装+TensorFlow安装+Keras安装+numpy安装(包含镜像和版本信息兼容问题)

Coinlist queuing tutorial to improve the winning rate
随机推荐
Upgrade cmake
kenlm
【openwrt】推荐一个国内开发的openwrt的版本,iStoreOS简介,非常好用,主要是做了一些优化。解决了汉化的问题。
单元测试覆盖率
第二十五周记录
Laravel document sorting 11. System architecture
GBASE 8s的隔离级别介绍
1. Phase II of the project - user registration and login
Detailed explanation of flex attributes in flex layout
小白学习MySQL - 统计的'投机取巧'
What is the storage engine and the three common database storage engines for MySQL
【LeetCode】148. Sort linked list
Anaconda安装+TensorFlow安装+Keras安装+numpy安装(包含镜像和版本信息兼容问题)
Laravel document sorting 3. CSRF protection
Record small knowledge points
mysql的tinyint字段类型判断的疑惑
The yii2 debug toolbar is missing
微信小程序父子组件之间传值
Nodejs 通过Heidisql连接mysql出现ER_BAD_DB_ERROR: Unknown database 'my_db_books'
Laravel document sorting 7. View





