当前位置:网站首页>机器学习深度学习——向量化
机器学习深度学习——向量化
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回归的梯度输出中去
边栏推荐
- CTF_ Web: file contains pseudo protocol with PHP
- 马斯克发布人形机器人,AI对马斯克为什么意义重大?
- Sourcetree pulls the code and prompts to fill in authentic, but the configuration cannot change the user
- i. Max development board learning record
- CTF_ Web:php weak type bypass and MD5 collision
- 关于TCP连接四次握手(或者叫四次挥手)的详细总结
- ThinkPHP is integrated with esaywechat. What's wrong with wechat payment callback without callback?
- 深度学习——几种学习类型
- Nodejs 通过Heidisql连接mysql出现ER_BAD_DB_ERROR: Unknown database 'my_db_books'
- CTF_ Web: basic 12 questions WP of attack and defense world novice zone
猜你喜欢
PHP extracts and analyzes table contents, and collects bidding information
English Grammar - pronunciation rules
关于TCP连接三次握手的详细总结
CTF_ Web: Learn flask template injection (SSTI) from 0
Finereport (sail soft) handling the problem that the histogram data label is blocked
LabVIEW开发气体调节器
CTF_ Web: advanced problem WP (5-8) of attack and defense world expert zone
Unit test coverage
95% of programmers fish here
1、项目第二阶段——用户注册和登陆
随机推荐
Thorough understanding of database transactions
Should I use on or where for the left join
Finereport (sail soft) handling the problem that the histogram data label is blocked
UCLA | generative pre training for black box optimization
Basic use of OBS browser+ browser
CMD operation MySQL in Windows
讲座记录《多种空间大地测量技术的数据处理方法和应用》
Laravel document sorting 11. System architecture
A detailed summary of TCP connection triple handshake
Error 1062 is reported during MySQL insertion, but I do not have this field.
What is data persistence?
php封装curl发送get、post请求方法,并使用
Laravel document sorting 9. Blade template
【esp32学习之路6——flash加密】
Lecture record: new application of inertial navigation - inertial measurement
LeetCode 剑指Offer II 091 粉刷房子[动态规划] HERODING的LeetCode之路
GBASE 8s的触发器
"Renaissance" in the digital age? The bottom digital collection makes people happy and sad
CTF_ Web: how to recognize and evaluate a regular expression
记录小知识点