矩阵链乘法问题描述(Matrix-chain multiplication)

来源:互联网 发布:单片机原理图怎么看 编辑:程序博客网 时间:2024/04/27 23:53

矩阵链乘法问题描述(Matrix-chain multiplication)

flyfish 2015-9-13
矩阵链乘法问题:给定n个要相乘的矩阵构成序列<A1,A2,...,An>,计算乘积A1,A2...An
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...An
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>乘积A1A2A3A4可用5种不同方式加全部括号:
if the chain of matrices is <A1,A2,A3,A4>,then we can fully parenthesized the product A1A2A3A4 in five distinct ways:

(A1(A2(A3A4)))
(A1((A2A3)A4))
((A1A2)(A3A4))
((A1(A2A3))A4)
(((A1A2)A3)A4)

只有当矩阵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个矩阵的链<A1A2A3>,假设维数分别为10X100,100X5,5X50。
如果按照(A1A2)A3次序计算,那么需要10x100x5 + 10x5x50 = 7500次乘法运算;
如果按照A1(A2A3)次序计算,那么需要100x5x50 + 10x100x50 = 75000次乘法运算;因此按照第一种次序计算要快10倍。
consider the problem of chain<A1A2A3> 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),we perform 10x100x5=5000 scalar multiplications to compute the 10x5 matrix product A1A2 , plus another 10 x 5 x50 = 2500 scalar multiplications to multiply this matrix by A3 , 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)) we perform 100 x 5 x 50 = 25,000 scalar multiplications to compute the 100 x 50 matrix product A2A3 , plus another 10 x 100 x 50 = 50,000 scalar multiplications to multiply A1 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

乘积AB是

AB={1×1+2×2+3×34×1+5×2+6×31×4+2×5+3×64×4+5×5+6×6}

2*3*2 理解为2行 每行中一个元素需要3个乘,一共2列
A1A2 结果是10行5列 每个元素100个乘.
A1A2 的结果 乘以 A3 结果是10行50列 每个元素5个乘.
所以是10x100x5 + 10x5x50 = 7500

矩阵链乘法问题可表述为:给定n个矩阵构成的一个链<A1A2A3>,其中i=1,2,3,4…..,n,矩阵Ai的维数为Pi1×Pi,对乘积A1A2A3.....An,以一种最小标量乘法次数的方式进行加全部括号。

We state the matrix-chain multiplication problem as follows: given a chain<A1A2A3> of n matrices, where for i=1,2,3,4…..,n matrix Ai has dimension Pi1×Pi , fully parenthesize the product A1A2A3.....An 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。

0 0