当前位置:网站首页>机器学习深度学习——向量化
机器学习深度学习——向量化
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回归的梯度输出中去
边栏推荐
- 记录小知识点
- 冰冰学习笔记:循环队列的实现
- Read lsd-slam: large scale direct monolithic slam
- BSC smart contract dividend mainstream currency | including marketing wallet | deflation | reflow | dividend free token | available for direct deployment
- Openmmlab environment configuration
- [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.
- Nodejs connects to MySQL through heidisql, and ER appears_ BAD_ DB_ ERROR: Unknown database 'my_ db_ books'
- mongodb集群
- GBASE 8s存储过程执行和删除
- GbASE 8s中的Blob 页(Blobspace page)
猜你喜欢

GBASE 8s 总体架构
![[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.

CTF_ Web: basic 12 questions WP of attack and defense world novice zone

Unity Quad culls shaders with back faces and transparent parts

Acmstreamopen return value problem

95% of programmers fish here

小白学习MySQL - 统计的'投机取巧'

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

什么是存储引擎以及MySQL常见的三种数据库存储引擎

EasyRecovery15非常好用的电脑数据恢复软件
随机推荐
GBASE 8s 索引B+树
kenlm
GBASE 8S内存管理
Flutter Builder & futurebuilder components
GBASE 8s的并行操作问题场景描述
GBASE 8s中DELIMIDENT环境变量的使用
Can Navicat directly operate the Android database SQLite
A-table mouse over the display hand, the current line can be clicked
GBASE 8s存储过程执行和删除
CTF_ Web: Advanced questions of attack and defense world expert zone WP (9-14)
Basic use of OBS browser+ browser
讲座记录《惯性导航的新应用——惯性测量》
简单的恶意样本行文分析-入门篇
kenlm
Synchronous and asynchronous functions (callback function, promise, generator, async/await)
CTF_ Web:php weak type bypass and MD5 collision
OBS Browser+浏览器的基本使用
openmmlab-环境配置
Retrofit 源码分析
GBASE 8s的数据导入和导出





