【机器学习入门基础】Matrix
Matrix
- 定义
- Matrix: Pectangular array of numbers
- dimension of matrix: the number of rows×\times×the number of column
- Matrix Element(entries of matrix)
- Vector: An n×\times× 1 matrix
- 1-indexed vs 0-index
- Scalar→\to→ 对象是单个值,不是vector or matrix.(标量)
- Matrix Addition
- Scalar Multiplication
- Combination of Operands
- Matrix-vector multiplication
- example
- Detail
- example
- house size:
- Matrix-matrix multiplication
- Details:
- example
- house size:
- Matrix multiplication
- Identity Matrix
- Example of identity matrix:
- Inverse and Transpose(逆运算以及转置矩阵)
- Matrix invers
- caculate the inverse matrix
- Octave
- Matlab
- Matrix Transpose
- example:
- the end
注:这里使用英文,感觉英文解释的更清楚
定义
Matrix: Pectangular array of numbers
dimension of matrix: the number of rows×\times×the number of column
4×24 \times 24×2matrix(R4×2R^{4\times2}R4×2)
[1902191137182194914371471448]\begin{bmatrix} {1902}&{191}\\ {1371}&{821}\\ {949}&{1437}\\ {147}&{1448}\\ \end{bmatrix}⎣⎢⎢⎡1902137194914719182114371448⎦⎥⎥⎤
2×32 \times 32×3matrix(R2×3R^{2\times3}R2×3)
[123456]\begin{bmatrix} {1}&{2}&{3}\\ {4}&{5}&{6}\\ \end{bmatrix}[142536]
Matrix Element(entries of matrix)
A=[1902191137182194914371471448]A=\left [ \begin{matrix} {1902}&{191}\\ {1371}&{821}\\ {949}&{1437}\\ {147}&{1448} \end{matrix} \right]A=⎣⎢⎢⎡1902137194914719182114371448⎦⎥⎥⎤
AijA_{ij}Aij:“i, j entry” in the ithi^{th}ith row, jthj^{th}jth column
A11A_{11}A11=1902 A12A_{12}A12=191 A32A_{32}A32=1437 A41A_{41}A41=147
A43A_{43}A43= undefined(error)(全部划掉)
Vector: An n×\times× 1 matrix
4-dimensional vector (R4R^4R4)
y=[460232315178]y=\left [ \begin{matrix} {460}\\ {232}\\ {315}\\ {178} \end{matrix} \right]y=⎣⎢⎢⎡460232315178⎦⎥⎥⎤
yiy_iyi=ithi^{th}ith element
y1y_1y1=460 y2y_2y2=232 y3y_3y3=315 y4y_4y4=178
1-indexed vs 0-index
y=[y1y2y3y4]y=\left [ \begin{matrix} {y_1}\\ {y_2}\\ {y_3}\\ {y_4} \end{matrix} \right]y=⎣⎢⎢⎡y1y2y3y4⎦⎥⎥⎤
y=[y0y1y2y3]y=\left [ \begin{matrix} {y_0}\\ {y_1}\\ {y_2}\\ {y_3} \end{matrix} \right]y=⎣⎢⎢⎡y0y1y2y3⎦⎥⎥⎤
Matices→\to→一般大写字母 Vector→\to→小写
Scalar→\to→ 对象是单个值,不是vector or matrix.(标量)
R→\to→the set of sccalar real numbers(标量实数集)
Rn→R^n\toRn→ n-dimensional vectors of real numbers(实数n维向量)
Matrix Addition
[102531]+[40.52502]=[50.541032]\begin{bmatrix} {1}&{0}\\ {2}&{5}\\ {3}&{1}\\ \end{bmatrix}+\begin{bmatrix} {4}&{0.5}\\ {2}&{5}\\ {0}&{2}\\ \end{bmatrix}=\begin{bmatrix} {5}&{0.5}\\ {4}&{10}\\ {3}&{2}\\ \end{bmatrix}⎣⎡123051⎦⎤+⎣⎡4200.552⎦⎤=⎣⎡5430.5102⎦⎤
3×2matrix+3×2matrix=3×2matrix3\times2 matrix+3\times2 matrix=3\times2 matrix3×2matrix+3×2matrix=3×2matrix
[102531]+[40.525]=error(没有意义)\begin{bmatrix} {1}&{0}\\ {2}&{5}\\ {3}&{1}\\ \end{bmatrix}+\begin{bmatrix} {4}&{0.5}\\ {2}&{5}\\ \end{bmatrix}=error( 没有意义)⎣⎡123051⎦⎤+[420.55]=error(没有意义)
Scalar Multiplication
3×[102531]=[3061593]=[102531]×33\times\begin{bmatrix} {1}&{0}\\ {2}&{5}\\ {3}&{1}\\ \end{bmatrix}=\begin{bmatrix} {3}&{0}\\ {6}&{15}\\ {9}&{3}\\ \end{bmatrix}=\begin{bmatrix} {1}&{0}\\ {2}&{5}\\ {3}&{1}\\ \end{bmatrix}\times33×⎣⎡123051⎦⎤=⎣⎡3690153⎦⎤=⎣⎡123051⎦⎤×3
[4063]/4=14[4063]=[103234]\begin{bmatrix} {4}&{0}\\ {6}&{3}\\ \end{bmatrix}/4=\frac{1}{4}\begin{bmatrix} {4}&{0}\\ {6}&{3}\\ \end{bmatrix}=\begin{bmatrix} {1}&{0}\\ {\frac{3}{2}}&{\frac{3}{4}}\\ \end{bmatrix}[4603]/4=41[4603]=[123043]
Combination of Operands
3×[142]+[005]−[302]/3=[3126]+[005]−[1323]=[2121013]3\times\begin{bmatrix} {1}\\ {4}\\ {2} \end{bmatrix}+\begin{bmatrix} {0}\\ {0}\\ {5} \end{bmatrix}-\begin{bmatrix} {3}\\ {0}\\ {2} \end{bmatrix}/3=\begin{bmatrix} {3}\\ {12}\\ {6} \end{bmatrix}+\begin{bmatrix} {0}\\ {0}\\ {5} \end{bmatrix}-\begin{bmatrix} {1}\\ {3}\\ {\frac{2}{3}} \end{bmatrix}=\begin{bmatrix} {2}\\ {12}\\ {10\frac{1}{3}} \end{bmatrix}3×⎣⎡142⎦⎤+⎣⎡005⎦⎤−⎣⎡302⎦⎤/3=⎣⎡3126⎦⎤+⎣⎡005⎦⎤−⎣⎡1332⎦⎤=⎣⎡2121031⎦⎤
Matrix-vector multiplication
example
[134021][15]=[1647]\begin{bmatrix} {1}&{3}\\ {4}&{0}\\ {2}&{1} \end{bmatrix}\begin{bmatrix} {1}\\ {5}\\ \end{bmatrix}=\begin{bmatrix} {16}\\ {4}\\ {7} \end{bmatrix}⎣⎡142301⎦⎤[15]=⎣⎡1647⎦⎤
1×1+3×5=161\times1+3\times5=161×1+3×5=16
4×1+0×5=44\times1+0\times5=44×1+0×5=4
2×1+1×5=72\times1+1\times5=72×1+1×5=7
(3×2matrix)(2×1matrix)=(3×1matrix)(3\times2 matrix) (2\times1matrix)=(3\times1matrix)(3×2matrix)(2×1matrix)=(3×1matrix)
Detail
[a11…a1n⋮⋱⋮am1…amn]×[x1⋮xn]=[y1⋮ym]\begin{bmatrix} {a_{11}}&\ldots&{a_{1n}} \\ {\vdots}&\ddots&{\vdots} \\ {a_{m1}}&\ldots&{a_{mn}} \\ \end{bmatrix}\times \begin{bmatrix} {x_{1}}\\ \vdots\\ {x_n} \end{bmatrix}=\begin{bmatrix} {y_1}\\ {\vdots}\\ {y_m} \end{bmatrix}⎣⎢⎡a11⋮am1…⋱…a1n⋮amn⎦⎥⎤×⎣⎢⎡x1⋮xn⎦⎥⎤=⎣⎢⎡y1⋮ym⎦⎥⎤
To get yiy_iyi, multiply A’s ithi^{th}ithrow with elements of vector x,and add them up.
example
[12150340−1−200][1321]=[1413−7]\begin{bmatrix} {1}&2&1&5\\ {0}&3&4&0\\ {-1}&{-2}&0&0 \end{bmatrix}\begin{bmatrix} 1\\3\\2\\1 \end{bmatrix}=\begin{bmatrix} 14\\13\\{-7} \end{bmatrix}⎣⎡10−123−2140500⎦⎤⎣⎢⎢⎡1321⎦⎥⎥⎤=⎣⎡1413−7⎦⎤
1×1+2×3+1×2+5×1=141\times1+2\times3+1\times2+5\times1=141×1+2×3+1×2+5×1=14
0×1+3×3+0×2+4×1=130\times1+3\times3+0\times2+4\times1=130×1+3×3+0×2+4×1=13
−1×1+−2×3+0×2+0×1=−7{-1}\times1+{-2}\times3+0\times2+0\times1={-7}−1×1+−2×3+0×2+0×1=−7
house size:
{210414161534852\begin{cases} 2104\\ 1416\\ 1534\\ 852 \end{cases}⎩⎪⎪⎪⎨⎪⎪⎪⎧210414161534852 hθ(x)=−a0+0.25xh_\theta(x)=-a0+0.25xhθ(x)=−a0+0.25x
[1210411416115341852]×[−400.25]=[−40×1+0.25×2104−40×1+0.25×1416−40×1+0.25×1534−40×1+0.25×842]→hθ(2104)→hθ(1416)→hθ(1534)→hθ(852)\begin{bmatrix} {1}&{2104}\\ {1}&{1416}\\ {1}&{1534}\\ {1}&{852}\\ \end{bmatrix}\times\begin{bmatrix} {-40}\\ {0.25}\\ \end{bmatrix}=\begin{bmatrix} {{-40}\times1+0.25\times2104}\\ {{-40}\times1+0.25\times1416}\\ {{-40}\times1+0.25\times1534}\\ {{-40}\times1+0.25\times842}\\ \end{bmatrix} \begin{matrix} \to h_\theta(2104)\\ \to h_\theta(1416)\\ \to h_\theta(1534)\\ \to h_\theta(852) \end{matrix}⎣⎢⎢⎡1111210414161534852⎦⎥⎥⎤×[−400.25]=⎣⎢⎢⎡−40×1+0.25×2104−40×1+0.25×1416−40×1+0.25×1534−40×1+0.25×842⎦⎥⎥⎤→hθ(2104)→hθ(1416)→hθ(1534)→hθ(852)
prediction=datamatrix∗*∗parameters
Matrix-matrix multiplication
[132401]×[130152]=[1110914]\begin{bmatrix} {1}&{3}&{2}\\ {4}&{0}&{1}\\ \end{bmatrix}\times\begin{bmatrix} {1}&{3}\\ 0&1 \\5&2 \end{bmatrix}=\begin{bmatrix} {11}&{10}\\ 9&14 \end{bmatrix}[143021]×⎣⎡105312⎦⎤=[1191014]
[132401]×[105]=[119]\begin{bmatrix} {1}&{3}&{2}\\ {4}&{0}&{1}\\ \end{bmatrix}\times\begin{bmatrix} {1}\\ 0 \\5 \end{bmatrix}=\begin{bmatrix} {11}\\ 9 \end{bmatrix}[143021]×⎣⎡105⎦⎤=[119]
[132401]×[312]=[1014]\begin{bmatrix} {1}&{3}&{2}\\ {4}&{0}&{1}\\ \end{bmatrix}\times\begin{bmatrix} {3}\\ 1 \\2 \end{bmatrix}=\begin{bmatrix} {10}\\ 14 \end{bmatrix}[143021]×⎣⎡312⎦⎤=[1014]
Details:
m×nmatrix+n×omatrix=n×omatrixA×B=Cm\times n {\kern 2pt} {matrix}+n\times o{\kern 2pt}matrix=n\times o{\kern 1pt}matrix\\ A\times B=Cm×nmatrix+n×omatrix=n×omatrixA×B=C
The ithi^{th}ith column of the matrix C is obtained by mutiplying A withthe ithi^{th}ith column of B(for i =1,2…\ldots…, o)
example
[1325]×[0132]=[971512]\begin{bmatrix} {1}&3\\ 2&5 \end{bmatrix}\times \begin{bmatrix} {0}&1\\ 3&2 \end{bmatrix}=\begin{bmatrix} {9}&7\\ 15&12 \end{bmatrix}[1235]×[0312]=[915712]
house size:
{210414161534852\begin{cases} 2104\\ 1416\\ 1534\\ 852 \end{cases}⎩⎪⎪⎪⎨⎪⎪⎪⎧210414161534852
Have 3 competing hypothesis
{1、hθ(x)=−40+0.25x1、hθ(x)=200+0.1x1、hθ(x)=−150+0.4x\begin{cases} 1、h_\theta (x)=-40+0.25x\\ 1、h_\theta (x)=200+0.1x\\ 1、h_\theta (x)=-150+0.4x\\ \end{cases}⎩⎪⎨⎪⎧1、hθ(x)=−40+0.25x1、hθ(x)=200+0.1x1、hθ(x)=−150+0.4x
[1210411416115431852]×[−40200−1500.250.10.4]=[482410692314342416344352464173285191]\begin{bmatrix} {1}&2104\\ 1&1416\\ 1&1543\\ 1&852 \end{bmatrix}\times \begin{bmatrix} {-40}&200&{-150}\\ 0.25&0.1&0.4 \end{bmatrix}=\begin{bmatrix} 482&410&692\\ 314&342&416 \\344&352&464\\ 173&285&191 \end{bmatrix}⎣⎢⎢⎡1111210414161543852⎦⎥⎥⎤×[−400.252000.1−1500.4]=⎣⎢⎢⎡482314344173410342352285692416464191⎦⎥⎥⎤
Matrix multiplication
3×5=5×33\times 5=5\times33×5=5×3 “Commutative”
Let Aand B be matrices.Then in general.
A×B≠B×AA\times B \ne B\times AA×B=B×A(not commutative)
E.g.[1100]×[0020]=[2000]≠[0020]×[1100]=[0022]E.g. \begin{bmatrix} {1}&1\\ 0&0\\ \end{bmatrix} \times\begin{bmatrix} {0}&0\\ 2&0\\ \end{bmatrix}=\begin{bmatrix} {2}&0\\ 0&0\\ \end{bmatrix}\\\ne\\\begin{bmatrix} {0}&0\\ 2&0\\ \end{bmatrix}\times \begin{bmatrix} {1}&1\\ 0&0\\ \end{bmatrix} =\begin{bmatrix} {0}&0\\ 2&2\\ \end{bmatrix}E.g.[1010]×[0200]=[2000]=[0200]×[1010]=[0202]
A×Bm×nn×mA×B∼m×mB×A∼n×n\begin{array}{|lll} A\times B\\ m\times n\quad n\times m\\ A\times B\sim m\times m \\ B\times A\sim n\times n \end{array}A×Bm×nn×mA×B∼m×mB×A∼n×n
Associative
3×5×2=(3×5)×2=3×(5×2)3\times 5\times2=({3\times 5})\times2=3\times (5\times2)3×5×2=(3×5)×2=3×(5×2)
A×B×C→(A×B)×C→A×(B×C)(sameanswer)A\times B\times C\quad \to (A\times B)\times C\\\quad\quad\quad\quad\quad\quad \to A\times (B\times C)(same\, answer)A×B×C→(A×B)×C→A×(B×C)(sameanswer)
Let D=B×\times×C. computeAA×DA\times DA×D
Let E=A×\times×B. computeAE×CE\times CE×C
Identity Matrix
Denoted III(or In×nI_{n\times n}In×n)\quad\quad\quad1∼identity1\sim identity1∼identity\quad\quad\quad
1×z=z×1=z1\times z=z\times 1=z1×z=z×1=z\quad\quad\quadfor any z
Example of identity matrix:
[1][1001][100010001][1000010000100001][11⋱1](Informally)\begin{bmatrix} 1 \end{bmatrix}\begin{bmatrix} {1}&0\\ 0&1\\ \end{bmatrix}\begin{bmatrix} 1&0&0\\ 0&1&0\\ 0&0&1 \end{bmatrix}\begin{bmatrix} 1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1 \end{bmatrix}\begin{bmatrix} 1&{}&{}&{} \\ {}&1&{}&{} \\ {}&{}& \ddots &{} \\ {}&{}&{}&1 \end{bmatrix}(Informally)[1][1001]⎣⎡100010001⎦⎤⎣⎢⎢⎡1000010000100001⎦⎥⎥⎤⎣⎢⎢⎡11⋱1⎦⎥⎥⎤(Informally)
For any matrix A
A×I=I×A=Am×nn×nm×mm×nm×nA\times I =I\times A=A\\m\times n\quad n\times n\quad m\times m\quad m\times n\quad m\times nA×I=I×A=Am×nn×nm×mm×nm×n
In×nNote:A×B≠B×AingeneralA×I=I×A✔I_{n\times n}\begin{array}{|lll} Note:\\ A\times B\ne B\times A \quad in \,general\\ A\times I= I\times A ✔ \end{array}In×nNote:A×B=B×AingeneralA×I=I×A✔
Inverse and Transpose(逆运算以及转置矩阵)
1=“Identity”\quad 3(3−1)=13(3^{-1})=13(3−1)=1\quad12(12−1)=112(12^{-1})=112(12−1)=1
Mot all numbers have an inverse\quad→0(0−1)\to0(0^{-1})→0(0−1)but 0−1→0^{-1}\to0−1→undefined
Matrix invers
If A is an m×mm\times mm×m matrix(square matrix{has the same row &column}),and if it has an inverse.
→AA−1=A−1A=I\to AA^{-1}=A^{-1}A=I→AA−1=A−1A=I\quadA逆矩阵A−1A逆矩阵A^{-1}A逆矩阵A−1\quad
A=[0000]无逆矩阵A=\begin{bmatrix} {0}&0\\ 0&0\\ \end{bmatrix}无逆矩阵A=[0000]无逆矩阵
E.g.[34216][0.4−0.1−0.050.75]=[1001]=I2×2E.g.\begin{bmatrix} 3&4\\ 2&16\\ \end{bmatrix}\begin{bmatrix} 0.4&{-0.1}\\ {-0.05}&0.75\\ \end{bmatrix}=\begin{bmatrix} 1&0\\ 0&1\\ \end{bmatrix}=I_{2\times 2}E.g.[32416][0.4−0.05−0.10.75]=[1001]=I2×2
the way to caculate
caculate the inverse matrix
Octave
A=[3 4;2 16]
pinv(A)
Matlab
Matrices that don’t have an inverse are “singular” or “degenerate”
Matrix Transpose
example:
A=[120359]A=\begin{bmatrix} 1&2&0\\ 3&5&9\\ \end{bmatrix}A=[132509]AT=[132509]\quad A^T=\begin{bmatrix} 1&3\\ 2&5\\ 0&9 \end{bmatrix}AT=⎣⎡120359⎦⎤row→column\quad row \to columnrow→column
Let A be a m×nm\times nm×n matrix,and letB=ATB=A^TB=AT
Then B is a n×mn\times mn×m matrix, and
Bij=AjiB_{ij}=A_{ji}Bij=Aji
B21=A12=2B_{21}=A_{12}=2B21=A12=2
B32=A23=9B_{32}=A_{23}=9B32=A23=9
the end
有相关配套程序请点击这里
【机器学习入门基础】Matrix相关推荐
- 机器学习入门基础(一)
机器学习简介 祖师爷 图灵,人工智能之父,最大成就图灵测试,就是一个机器和一个人跟你聊天,你不知道对方是人还是机器,如果经过聊天后,你分辨不出谁是人谁是机器说明这个机器通过了图灵测试. 人工智能和机器 ...
- 机器学习入门基础(二)
不纯度 决策树的每个根节点和中间节点中都会包含一组数据(工作为公务员为某一个节点),在这组数据中,如果有某一类标签占有较大的比例,我们就说该节点越"纯",分枝分得好.某一类标签占的 ...
- 机器学习——入门基础
文章目录 西瓜书机器学习第二章 模型评估和选择 一种训练集一种算法 模型的评估方法 性能度量值 一种训练集多种算法 P-R曲线 ROC曲线 多种训练集一种算法 代价敏感错误率和代价曲线 测试集上的性能 ...
- 写了本机器学习入门书
最近写了一本机器学习的入门书,针对初学者,希望能给初学者雪中送炭. 黄海广 动机 作为计算机方向的博士,本人一直热衷于帮助机器学习初学者入门方面的工作,主持和参与了很多国内外优秀作品的翻译.代码复现工 ...
- 干货丨先搞懂这八大基础概念,再谈机器学习入门
翻译 | AI科技大本营 参与 | 林椿眄 准备好开始AI了吗?可能你已经开始了在机器学习领域的实践学习,但是依然想要扩展你的知识并进一步了解那些你听过却没有时间了解的话题. 这些机器学习的专业术语能 ...
- 学python的基础-老司机学python篇:第一季(基础速过、机器学习入门)
本课程正在限时优惠中,请尽快购买 原价:¥350 优惠价:¥999.00 章节导航 课程大纲 第一章:python基础速过篇 开张课.我们直接开门见山,对着文档先把最基本的东西学一下.注意:关键看视频 ...
- 机器学习入门 笔记(二) 机器学习基础概念
第二章 机器学习基础概念 1.机器的数据 2.机器学习的主要任务 3.监督学习和非监督学习 4.批量.在线学习.参数.非参数学习 5.哲学思考 6.环境的搭建 1.机器的数据 我们以鸢尾花的数据为例. ...
- 机器学习入门一:基础知识
机器学习入门一:基础知识 前言 机器学习介绍 1.什么是机器学习? 2.机器学习中的常见困难 模型的泛化[^1] (Generalization)能力 3.机器学习中数据集划分 4.机器学习中几种学习 ...
- 机器学习零基础初学者入门
机器学习入门系列以本文为主导线,中间穿插着其他概念与网址 机器学习概述 定义 机器学习是一种在没有具体编程的情况下教计算机学习的能力.例如,机器学习通常被用来训练计算机来执行一些难以用编程手段来完成的 ...
最新文章
- Java 内存泄漏监控检测与分析
- 可解释性 or 准确性?AI 模型就一定不能两者兼得吗?
- windows中安装Node.js-安装angular-cli
- php4.3-5.x,4.3 案例之 ThinkPHP 5.0 集成方法
- 导入数据任务(id:373985)异常, 错误信息:解析导入文件错误,请检查导入文件内容,仅支持导入json格式数据及excel文件
- 设计模式学习笔记:六大原则
- 数字音视频技术:音频中的一些概念(采样率, 位深度, 声道数, Sample/Frame/Packet)
- 第一章 初识Linux shell
- webServer tomcat5/tomcat6/tomcat7诠释
- Jenkins发布spring boot到hub.Docker 方法
- LeetCode 6. Z 字形变换(找规律)
- 今天懒一次 豆瓣电影Top250
- 在线抽签html,抽签网页板代码
- 操作系统文件系统练习题
- 惨!美团程序员的年终奖金可能没了
- 服务器租用价格与哪些因素有关?
- android xml画斜线,API返回XML引号通过反斜线
- 我的jQuery学习之路_笔记(三)
- 电脑没有串口怎么办?
- 如何使用微软官方工具制作win10启动盘
热门文章
- android 最新微信红包,分享Android微信红包插件
- 【原创】Visio软件绘图功能极佳----记我的第一次Visio软件绘制时序图
- 程序员眼中的中国传统文化-王阳明《传习录》5
- 国外设计公司H5网站模板
- 华为鸿蒙os手机版,华为鸿蒙os2.0系统正式版安装包下载-华为鸿蒙2.0系统手机版v2.0安卓版_289手游网下载...
- 陀螺仪偏航角的夹角计算方法
- 【浙江大学C小程week6知识点整理】
- vga分屏2个显示器_VGA多分屏聚合器和有趣的问题
- NGK韩国峰会完美落幕,共议区块链生态新发展
- SQL Server 异常 COM 类公司中CLSID 为 {10021F00-E260-11CF-AE68-00AA004A34D5} 的组件时失败,原因是出现以下错误: 80040154