当前位置:网站首页>机器学习深度学习——向量化
机器学习深度学习——向量化
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回归的梯度输出中去
边栏推荐
- 什么是数据持久化?
- Laravel document sorting 6. Response
- English Grammar - pronunciation rules
- 95% of programmers fish here
- [kubernetes series] installation and use of Helm
- Numpy NP tips: squeeze and other processing of numpy arrays
- Shutter fittedbox component
- [openwrt] we recommend a domestically developed version of openwrt, an introduction to istoreos. It is very easy to use. It is mainly optimized. It solves the problem of Sinicization.
- GBASE 8S内存管理
- GBASE 8s的级联删除功能
猜你喜欢

Lecture record: new application of inertial navigation - inertial measurement

mongodb集群

记录小知识点

Read lsd-slam: large scale direct monolithic slam

1280_ C language to find the average value of two unsigned integer

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

1. Phase II of the project - user registration and login
![[openwrt] we recommend a domestically developed version of openwrt, an introduction to istoreos. It is very easy to use. It is mainly optimized. It solves the problem of Sinicization.](/img/62/6152d5a30c92a340cb286c7b1cbc54.png)
[openwrt] we recommend a domestically developed version of openwrt, an introduction to istoreos. It is very easy to use. It is mainly optimized. It solves the problem of Sinicization.

Coinlist queuing tutorial to improve the winning rate

Anaconda installation +tensorflow installation +keras installation +numpy installation (including image and version information compatibility issues)
随机推荐
CTF_ Web: Advanced questions of attack and defense world expert zone WP (1-4)
Lecture record: new application of inertial navigation - inertial measurement
GBASE 8s的数据导入和导出
CTF_ Web: Advanced questions of attack and defense world expert zone WP (15-18)
1、项目第二阶段——用户注册和登陆
Laravel document sorting 11. System architecture
【LeetCode】22. bracket-generating
LeetCode 剑指Offer II 091 粉刷房子[动态规划] HERODING的LeetCode之路
Smart contract learning materials
无法安装redis接口
2021.8.29 notes: register, bit operation, pointer, structure
CTF_ Web: Advanced questions of attack and defense world expert zone WP (9-14)
GBase 8s的封锁技术的基本介绍
SQL注入详解
SQL injection details
Upgrade cmake
"How to carry out industrial positioning" in local / Park industrial planning
GBASE 8s存储过程流程控制
Failed to install redis interface
How to draw an industry investment map





