strassen算法

Posted corfox_liu

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了strassen算法相关的知识,希望对你有一定的参考价值。

strassen算法:

     第一步:分解输入矩阵A、B和输出矩阵C为n/2xn/2的子矩阵。A--->A11、A12、A21、A22, B---->B11、B12、B21、B22,  C---->C11,C12,C21,C22

     第二步:创建十个矩阵

                                           S1=B12 - B22

                                           S2=A11 + A12

                                           S3 = A21 + A22

                                           S4 = B21 - B11

                                           S5 = A11 + A22

                                           S6 = B11 + B22

                                           S7 = A12 + A22

                                           S8 = B21 + B22

                                           S9 = A11 - A21

                                           S10 = B11 + B22

      第三步:递归七个矩阵积

                                           P1 = A11 * S1

                                           P2 = B22 * S2

                                           P3 = B11 * S3

                                           P4 = A22 * S4

                                           P5 = S5 * S6

                                           P6 = S7 * S8

                                           P7 = S9 * S10

      第四步:计算出结果矩阵的子矩阵

                                            C11 = P5 + P4 - P2 + P6

                                            C12 = P1 + P2

                                            C21 = P3 + P4

                                            C22 = P5 + P1 - P3 - P7


Strassn算法运行时间T(n)的递归式:

                                                            T(n) = 7 * T(n / 2) + theta(n^2)      当 n > 1

                                                             T(n) = theta(1)               当n = 1

由主定理,f(n) = theta(n^2) = O(n^log2(7)),所以T(n) = theta(n^log2(7)),约等于theta(n^log2(2.807))。对于一般的矩阵乘法来说,时间复杂度的最小下界是theta(n^2),因为有结果矩阵由n^2个元素。


参见《算法导论》


以上是关于strassen算法的主要内容,如果未能解决你的问题,请参考以下文章

Python 实现中的 Strassen 算法错误

为啥我的 strassen 算法不适用于 3x3 矩阵?

Strassen算法不是最快的吗?

实施 Strassen 矩阵乘法算法的问题

矩阵乘法的Strassen算法及时间复杂度

使用 Strassen 算法将 2 个数字与 n 位相乘的算法