矩阵链乘法问题描述(Matrix-chain multiplication)
2015-09-13 14:44
363 查看
矩阵链乘法问题描述(Matrix-chain multiplication)
flyfish 2015-9-13
矩阵链乘法问题:给定n个要相乘的矩阵构成序列<A1,A2,...,An>,计算乘积A1,A2...AnA_1,A_2...A_n。
Matrix-chain multiplication:We are given a sequence(chain)<A1,A2,...,An> or n matices to be multiplied,and we wish to compute the product A1,A2...AnA_1,A_2...A_n。
product
n乘积
multiply
英 [‘mʌltɪplaɪ] 美 [‘mʌltɪplaɪ]
vt. 乘;使增加;使繁殖;使相乘
vi. 乘;繁殖;增加
过去式 multiplied
过去分词 multiplied
现在分词 multiplying
为了计算,可以将两个矩阵相乘的算法作为一个子程序,根据括号的次序做全部的矩阵乘法。
We can evaluate the express using the stand algorithm for multiplying paires of matrices as a subroutine once we have parenthesized it to resolve all ambiguities in how the matrices are multiplied together.
parenthesize
英 [pə’renθɪsaɪz] 美 [pə’rɛnθə,saɪz]
vt. 加插入语于…;将…加上括弧
过去式 parenthesized
过去分词 parenthesized
现在分词 parenthesizing
ambiguity
英 [æmbɪ’gjuːɪtɪ] 美 [,æmbɪ’ɡjuəti]
n. 含糊;不明确;暧昧;模棱两可的话
复数 ambiguities
如果矩阵链为<A1,A2,A3,A4>乘积A1A2A3A4A_1A_2A_3A_4可用5种不同方式加全部括号:
if the chain of matrices is <A1,A2,A3,A4>,then we can fully parenthesized the product A1A2A3A4A_1A_2A_3A_4 in five distinct ways:
(A1(A2(A3A4)))(A_1 (A_2 (A_3 A_4 )))
(A1((A2A3)A4))(A_1 ((A_2 A_3 )A_4 ))
((A1A2)(A3A4))((A_1 A_2 )(A_3 A_4 ))
((A1(A2A3))A4)((A_1 (A_2 A_3 ))A_4 )
(((A1A2)A3)A4)(((A_1 A_2 )A_3 )A_4 )
只有当矩阵A的列数与矩阵B的行数相等时A×B才有意义
如果A是p*q矩阵,B是q*r矩阵,那么结果的矩阵C就是p*r矩阵
We can multiple tow metrices A and B only if they are compatible:the number of colums of A must equal the number of rows of B.
if A is a p*q matrix and
B is a q*r matrix,
the resulting matrix C is a p*r matrix
考虑3个矩阵的链<A1,A2,A3>,假设维数分别为10X100,100X5,5X50。
如果按照(A1A2)A3次序计算,那么需要10x100x5 + 10x5x50 = 7500次乘法运算;
如果按照A1(A2A3)次序计算,那么需要100x5x50 + 10x100x50 = 75000次乘法运算;因此按照第一种次序计算要快10倍。
consider the problem of chain<A1,A2,A3> of three matrices,Suppose that the dimensions of the matrices are 10x100,100x5,and 5x50,
respectively,If we multiply according to the parenthesization((A1A2)A3)((A_1 A_2) A_3),we perform 10x100x5=5000 scalar multiplications to compute the 10x5 matrix product A1A2A_1 A_2 , plus another 10 x 5 x50 = 2500 scalar multiplications to multiply this matrix by A3A_3 , for a total of 7500 scalar multiplications.
respective
英 [rɪ’spektɪv] 美 [rɪ’spɛktɪv]
adj. 分别的,各自的
respectively
英 [rɪ’spektɪvlɪ] 美 [rɪ’spɛktɪvli]
adv. 分别地;各自地,独自地
If instead we multiply according to the parenthesization(A1(A2A3))(A_1 (A_2 A_3)) we perform 100 x 5 x 50 = 25,000 scalar multiplications to compute the 100 x 50 matrix product A2A3A_2 A_3 , plus another 10 x 100 x 50 = 50,000 scalar multiplications to multiply A1A_1 by this matrix, for a total of 75,000 scalar multiplications. Thus, computing the product according tothe first parenthesization is 10 times faster.
假设矩阵 A B
A 2行3列
B 3行2列
A={142536},B=⎧⎩⎨⎪⎪123456⎫⎭⎬⎪⎪\begin{equation*}A=\begin{Bmatrix}
1 & 2 & 3\\
4 & 5& 6
\end{Bmatrix},
B=\begin{Bmatrix}
1 & 4\\
2 & 5\\
3 & 6
\end{Bmatrix}
\end{equation*}
乘积AB是
AB={1×1+2×2+3×34×1+5×2+6×31×4+2×5+3×64×4+5×5+6×6}\begin{equation*}AB=\begin{Bmatrix}
1\times 1+2\times 2+3\times 3 & 1\times 4+2\times 5+3\times 6 \\
4\times 1+5\times 2+6\times 3 & 4\times 4+5\times 5+6\times 6
\end{Bmatrix}
\end{equation*}
2*3*2 理解为2行 每行中一个元素需要3个乘,一共2列
A1A2A_1 A_2 结果是10行5列 每个元素100个乘.
A1A2A_1 A_2 的结果 乘以 A3A_3 结果是10行50列 每个元素5个乘.
所以是10x100x5 + 10x5x50 = 7500
矩阵链乘法问题可表述为:给定n个矩阵构成的一个链<A1,A2,A3>,其中i=1,2,3,4…..,n,矩阵AiA_i的维数为Pi1×PiPi_1 ×Pi,对乘积A1A2A3.....AnA_1A_2A_3.....A_n,以一种最小标量乘法次数的方式进行加全部括号。
We state the matrix-chain multiplication problem as follows: given a chain<A1,A2,A3> of n matrices, where for i=1,2,3,4…..,n matrix AiA_i has dimension Pi1×PiPi_1 ×Pi , fully parenthesize the product A1A2A3.....AnA_1A_2A_3.....A_n in a way that minimizes the number of scalar multiplications.
注意在矩阵链相乘题目中,实际上并没有把矩阵相乘,目的仅是确定一个具有最小代价的矩阵相乘次序
Note that in the matrix-chain multiplication problem, we are not actually multiplying matrices. Our goal is only to determine an order for multiplying matrices that has the lowest cost。
flyfish 2015-9-13
矩阵链乘法问题:给定n个要相乘的矩阵构成序列<A1,A2,...,An>,计算乘积A1,A2...AnA_1,A_2...A_n。
Matrix-chain multiplication:We are given a sequence(chain)<A1,A2,...,An> or n matices to be multiplied,and we wish to compute the product A1,A2...AnA_1,A_2...A_n。
product
n乘积
multiply
英 [‘mʌltɪplaɪ] 美 [‘mʌltɪplaɪ]
vt. 乘;使增加;使繁殖;使相乘
vi. 乘;繁殖;增加
过去式 multiplied
过去分词 multiplied
现在分词 multiplying
为了计算,可以将两个矩阵相乘的算法作为一个子程序,根据括号的次序做全部的矩阵乘法。
We can evaluate the express using the stand algorithm for multiplying paires of matrices as a subroutine once we have parenthesized it to resolve all ambiguities in how the matrices are multiplied together.
parenthesize
英 [pə’renθɪsaɪz] 美 [pə’rɛnθə,saɪz]
vt. 加插入语于…;将…加上括弧
过去式 parenthesized
过去分词 parenthesized
现在分词 parenthesizing
ambiguity
英 [æmbɪ’gjuːɪtɪ] 美 [,æmbɪ’ɡjuəti]
n. 含糊;不明确;暧昧;模棱两可的话
复数 ambiguities
如果矩阵链为<A1,A2,A3,A4>乘积A1A2A3A4A_1A_2A_3A_4可用5种不同方式加全部括号:
if the chain of matrices is <A1,A2,A3,A4>,then we can fully parenthesized the product A1A2A3A4A_1A_2A_3A_4 in five distinct ways:
(A1(A2(A3A4)))(A_1 (A_2 (A_3 A_4 )))
(A1((A2A3)A4))(A_1 ((A_2 A_3 )A_4 ))
((A1A2)(A3A4))((A_1 A_2 )(A_3 A_4 ))
((A1(A2A3))A4)((A_1 (A_2 A_3 ))A_4 )
(((A1A2)A3)A4)(((A_1 A_2 )A_3 )A_4 )
只有当矩阵A的列数与矩阵B的行数相等时A×B才有意义
如果A是p*q矩阵,B是q*r矩阵,那么结果的矩阵C就是p*r矩阵
We can multiple tow metrices A and B only if they are compatible:the number of colums of A must equal the number of rows of B.
if A is a p*q matrix and
B is a q*r matrix,
the resulting matrix C is a p*r matrix
考虑3个矩阵的链<A1,A2,A3>,假设维数分别为10X100,100X5,5X50。
如果按照(A1A2)A3次序计算,那么需要10x100x5 + 10x5x50 = 7500次乘法运算;
如果按照A1(A2A3)次序计算,那么需要100x5x50 + 10x100x50 = 75000次乘法运算;因此按照第一种次序计算要快10倍。
consider the problem of chain<A1,A2,A3> of three matrices,Suppose that the dimensions of the matrices are 10x100,100x5,and 5x50,
respectively,If we multiply according to the parenthesization((A1A2)A3)((A_1 A_2) A_3),we perform 10x100x5=5000 scalar multiplications to compute the 10x5 matrix product A1A2A_1 A_2 , plus another 10 x 5 x50 = 2500 scalar multiplications to multiply this matrix by A3A_3 , for a total of 7500 scalar multiplications.
respective
英 [rɪ’spektɪv] 美 [rɪ’spɛktɪv]
adj. 分别的,各自的
respectively
英 [rɪ’spektɪvlɪ] 美 [rɪ’spɛktɪvli]
adv. 分别地;各自地,独自地
If instead we multiply according to the parenthesization(A1(A2A3))(A_1 (A_2 A_3)) we perform 100 x 5 x 50 = 25,000 scalar multiplications to compute the 100 x 50 matrix product A2A3A_2 A_3 , plus another 10 x 100 x 50 = 50,000 scalar multiplications to multiply A1A_1 by this matrix, for a total of 75,000 scalar multiplications. Thus, computing the product according tothe first parenthesization is 10 times faster.
假设矩阵 A B
A 2行3列
B 3行2列
A={142536},B=⎧⎩⎨⎪⎪123456⎫⎭⎬⎪⎪\begin{equation*}A=\begin{Bmatrix}
1 & 2 & 3\\
4 & 5& 6
\end{Bmatrix},
B=\begin{Bmatrix}
1 & 4\\
2 & 5\\
3 & 6
\end{Bmatrix}
\end{equation*}
乘积AB是
AB={1×1+2×2+3×34×1+5×2+6×31×4+2×5+3×64×4+5×5+6×6}\begin{equation*}AB=\begin{Bmatrix}
1\times 1+2\times 2+3\times 3 & 1\times 4+2\times 5+3\times 6 \\
4\times 1+5\times 2+6\times 3 & 4\times 4+5\times 5+6\times 6
\end{Bmatrix}
\end{equation*}
2*3*2 理解为2行 每行中一个元素需要3个乘,一共2列
A1A2A_1 A_2 结果是10行5列 每个元素100个乘.
A1A2A_1 A_2 的结果 乘以 A3A_3 结果是10行50列 每个元素5个乘.
所以是10x100x5 + 10x5x50 = 7500
矩阵链乘法问题可表述为:给定n个矩阵构成的一个链<A1,A2,A3>,其中i=1,2,3,4…..,n,矩阵AiA_i的维数为Pi1×PiPi_1 ×Pi,对乘积A1A2A3.....AnA_1A_2A_3.....A_n,以一种最小标量乘法次数的方式进行加全部括号。
We state the matrix-chain multiplication problem as follows: given a chain<A1,A2,A3> of n matrices, where for i=1,2,3,4…..,n matrix AiA_i has dimension Pi1×PiPi_1 ×Pi , fully parenthesize the product A1A2A3.....AnA_1A_2A_3.....A_n in a way that minimizes the number of scalar multiplications.
注意在矩阵链相乘题目中,实际上并没有把矩阵相乘,目的仅是确定一个具有最小代价的矩阵相乘次序
Note that in the matrix-chain multiplication problem, we are not actually multiplying matrices. Our goal is only to determine an order for multiplying matrices that has the lowest cost。
相关文章推荐
- go中的main函数和init函数
- 你应该知道的最好Webmail邮件客户端
- 线程中sleep和wait有什么区别
- Command-通过命令转发接受者/Chain of Resposibility客户端调整处理函数顺序
- Gephi弹出JVM Creation failed
- STL学习之pair
- [STL] pair
- 图像滤镜艺术---Oilpaint油画滤镜
- [LeetCode#265] Paint House II
- [LeetCode#256] Paint House
- aide上课内容
- 项目中使用了个quartz包,启动时提示Quartz version update check failed
- The available repos for opensuse13.2
- iterator_traits 存在的作用与意义
- codeforces 159D D. Palindrome pairs( manacher+dp )
- UVA 573 The Snail
- Linux学习之进程fork()、exec、exit()/_exit()、wait()/waitpid
- USACO 1.3 Barn Repair (快排+贪心)
- Terrain maps
- 广义表的head与tail的基本用法