当前位置:网站首页>【机器学习】向量化计算 -- 机器学习路上必经路
【机器学习】向量化计算 -- 机器学习路上必经路
2022-07-01 02:45:00 【计算机魔术师】
欢迎来到
魔术之家!!该文章收录专栏
— 机器学习 —专栏内容
— 【机器学习】浅谈正规方程法&梯度下降 —
— 【机器学习】梯度下降之数据标准化 —
— 【机器学习】logistic分类回归算法—
— 第十届“泰迪杯“感谢学习总结—
一、求解矩阵
在求解矩阵中,往往有很多很好的,经过高度优化的线性代数库,如octave,matlib,python numpy, c++,java.
我们使用这些线性代数库,可以短短几行实现 所要的效果。
阅读本文内容(需要一点点线性代数的知识)
二、例一
例如 求公式:
h ( x ) = ∑ i = 1 n θ i ∗ x i h(x) = \sum_{i=1}^n\theta_i*x_i h(x)=∑i=1nθi∗xi
我们可以通过循环每一个值来求 每一个 i i i所对应的结果,但此时循环的时间复杂度为 O ( n ) O(n) O(n) , 我们可以把 θ i ( i = 1 , 2 , 3... n ) \theta_i(i=1,2,3...n) θi(i=1,2,3...n) 看为 n n n维的列向量, x i x_i xi作为 n n n维的列向量,则原公式即为求两个向量的内积 θ T ∗ x i \theta^T*x_i θT∗xi 来求得方程,这样在numpy中仅仅需要一行代码。如下图(演示代码为octave(matlib开源版)
)
c++实现
三、例二
- 再看一个复杂一点的例子:
(对梯度下降还不了解建议先食用文章:机器学习】浅谈正规方程法&梯度下降)
在梯度下降(Gradient descent)同步更新参数 θ i ( i = 1 , 2 , 3... m ) 中 \theta_i(i=1,2,3...m)中 θi(i=1,2,3...m)中
我们可以通过循环 i i i得到每个参数更新,但我们是否能用例子一的方法 简化呢,
如图:
我们将所求式子变为 向量之间的运行,
θ = θ − α ∗ δ \theta = \theta - \alpha * δ θ=θ−α∗δ
(其中: δ δ δ = ∑ x = 1 n ( h θ ( x ) − y i ) 2 n ∗ x i \sum_{x=1}^n \frac{(h_\theta(x) - y_i)^2}{ n }*x_i ∑x=1nn(hθ(x)−yi)2∗xi, h θ ( x ) − y i h_\theta(x) - y_i hθ(x)−yi 是一个实数, x i x_i xi是特征维度的列向量)
此时参数 θ i \theta_i θi也能同步更新,符合要求
四、写在最后
在面对,数据为百万级别,千万级别,或者特征为百万级别,特征级别,向量化计算对提高运算效率非常高效,比
for
循环要好用得多,这在机器学习中是非常常见的,一定要掌握
边栏推荐
- DenseNet网络论文学习笔记
- I want to know how to open a stock account? Is it safe to open an account online?
- Mouse over effect 10
- SAP ALV summary is inconsistent with exported excel summary data
- How to use Jieba participle in unity
- Restcloud ETL practice data row column conversion
- MCU firmware packaging Script Software
- Complete training and verification of a neural network based on pytorch
- go: finding module for package
- 股票开户安全吗?上海股票开户步骤。
猜你喜欢
Mnasnet learning notes
Focusing on green and low carbon, data center cooling has entered a new era of "intelligent cooling"
Comment réaliser la liaison entre la serrure intelligente et la lampe, la scène du moteur de rideau intelligent dans le timing intelligent?
lavaweb【初识后续问题的解决】
PCB defect detection based on OpenCV and image subtraction
servlet【初识】
记一次服务部署失败问题排查
Restcloud ETL practice to realize incremental data synchronization without identification bit
DenseNet网络论文学习笔记
在unity中使用jieba分词的方法
随机推荐
import tensorflow.contrib.slim as slim报错
Mouse over effect 9
大橙子疯博客搬家通知
nacos配置中心使用教程
ANR问题的分析与解决思路
Evaluation of the entry-level models of 5 mainstream smart speakers: apple, Xiaomi, Huawei, tmall, Xiaodu, who is better?
UE4 rendering pipeline learning notes
[JS] [Nuggets] get people who are not followers
In the industrial Internet, "small" programs have "big" effects
单片机 MCU 固件打包脚本软件
产业互联网中,「小」程序有「大」作为
园区运营效率提升,小程序容器技术加速应用平台化管理
Thread Detach
Comment réaliser la liaison entre la serrure intelligente et la lampe, la scène du moteur de rideau intelligent dans le timing intelligent?
Mouse over effect 10
Gartner研究:在中国,混合云的采用已成为主流趋势
Map array function
Visual effects, picture to cartoon function
视觉特效,图片转成漫画功能
最新微信ipad协议 CODE获取 公众号授权等