日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

算法中的Strassen矩阵乘法

發(fā)布時(shí)間:2023/12/1 编程问答 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 算法中的Strassen矩阵乘法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Introduction

介紹

Strassen in 1969 which gives an overview that how we can find the multiplication of two 2*2 dimension matrix by the brute-force algorithm. But by using divide and conquer technique the overall complexity for multiplication two matrices is reduced. This happens by decreasing the total number if multiplication performed at the expenses of a slight increase in the number of addition.

Strassen在1969年概述了如何用蠻力算法找到兩個(gè)2 * 2維矩陣的乘法。 但是通過(guò)使用分而治之技術(shù),兩個(gè)矩陣相乘的整體復(fù)雜度降低了。 如果以乘法數(shù)略有增加為代價(jià)執(zhí)行乘法,則會(huì)通過(guò)減少總數(shù)來(lái)實(shí)現(xiàn)。

For multiplying the two 2*2 dimension matrices Strassen's used some formulas in which there are seven multiplication and eighteen addition, subtraction, and in brute force algorithm, there is eight multiplication and four addition. The utility of Strassen's formula is shown by its asymptotic superiority when order n of matrix reaches infinity. Let us consider two matrices A and B, n*n dimension, where n is a power of two. It can be observed that we can contain four n/2*n/2 submatrices from A, B and their product C. C is the resultant matrix of A and B.

為了將兩個(gè)2 * 2維矩陣相乘, 斯特拉森使用了一些公式,其中有七個(gè)乘法和十八個(gè)加法,減法,在蠻力算法中,有八個(gè)乘法和四個(gè)加法。 Strassen公式的效用由矩陣階數(shù)n達(dá)到無(wú)窮大時(shí)的漸近優(yōu)越性表示。 讓我們考慮兩個(gè)矩陣A和B , n * n維,其中n是2的冪。 可以觀察到,我們可以包含來(lái)自A , B及其乘積C的四個(gè)n / 2 * n / 2個(gè)子矩陣。 C是A和B的合成矩陣。

Strassen矩陣乘法的過(guò)程 (Procedure of Strassen matrix multiplication)

There are some procedures:

有一些過(guò)程:

  • Divide a matrix of order of 2*2 recursively till we get the matrix of 2*2.

    遞歸除以2 * 2的矩陣,直到得到2 * 2的矩陣。

  • Use the previous set of formulas to carry out 2*2 matrix multiplication.

    使用前面的一組公式進(jìn)行2 * 2矩陣乘法。

  • In this eight multiplication and four additions, subtraction are performed.

    在這八個(gè)乘法和四個(gè)加法中,執(zhí)行減法。

  • Combine the result of two matrixes to find the final product or final matrix.

    合并兩個(gè)矩陣的結(jié)果以找到最終乘積或最終矩陣。

  • Stassen矩陣乘法的公式 (Formulas for Stassen’s matrix multiplication)

    In Strassen’s matrix multiplication there are seven multiplication and four addition, subtraction in total.

    在Strassen的矩陣乘法中,總共有七個(gè)乘法和四個(gè)加減法。

    1. D1 = (a11 + a22) (b11 + b22)2. D2 = (a21 + a22).b113. D3 = (b12 – b22).a114. D4 = (b21 – b11).a225. D5 = (a11 + a12).b226. D6 = (a21 – a11) . (b11 + b12)7. D7 = (a12 – a22) . (b21 + b22)C11 = d1 + d4 – d5 + d7C12 = d3 + d5C21 = d2 + d4C22 = d1 + d3 – d2 – d6

    Strassen矩陣乘法的算法 (Algorithm for Strassen’s matrix multiplication)

    Algorithm Strassen(n, a, b, d)

    算法Strassen(n,a,b,d)

    begin If n = threshold then computeC = a * b is a conventional matrix.ElsePartition a into four sub matrices a11, a12, a21, a22.Partition b into four sub matrices b11, b12, b21, b22.Strassen ( n/2, a11 + a22, b11 + b22, d1)Strassen ( n/2, a21 + a22, b11, d2)Strassen ( n/2, a11, b12 – b22, d3)Strassen ( n/2, a22, b21 – b11, d4)Strassen ( n/2, a11 + a12, b22, d5)Strassen (n/2, a21 – a11, b11 + b22, d6)Strassen (n/2, a12 – a22, b21 + b22, d7)C = d1+d4-d5+d7 d3+d5d2+d4 d1+d3-d2-d6 end ifreturn (C) end.

    Strassen矩陣乘法代碼 (Code for Strassen matrix multiplication)

    .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} .minHeight{min-height: 250px;}@media (min-width: 1025px){.minHeight{min-height: 90px;}} #include <stdio.h>int main() {int a[2][2],b[2][2],c[2][2],i,j;int m1,m2,m3,m4,m5,m6,m7;printf("Enter the 4 elements of first matrix: ");for(i=0;i<2;i++)for(j=0;j<2;j++)scanf("%d",&a[i][j]);printf("Enter the 4 elements of second matrix: ");for(i=0;i<2;i++)for(j=0;j<2;j++)scanf("%d",&b[i][j]);printf("\nThe first matrix is\n");for(i=0;i<2;i++){printf("\n");for(j=0;j<2;j++)printf("%d\t",a[i][j]);}printf("\nThe second matrix is\n");for(i=0;i<2;i++){printf("\n");for(j=0;j<2;j++)printf("%d\t",b[i][j]);}m1= (a[0][0] + a[1][1])*(b[0][0]+b[1][1]);m2= (a[1][0]+a[1][1])*b[0][0];m3= a[0][0]*(b[0][1]-b[1][1]);m4= a[1][1]*(b[1][0]-b[0][0]);m5= (a[0][0]+a[0][1])*b[1][1];m6= (a[1][0]-a[0][0])*(b[0][0]+b[0][1]);m7= (a[0][1]-a[1][1])*(b[1][0]+b[1][1]);c[0][0]=m1+m4-m5+m7;c[0][1]=m3+m5;c[1][0]=m2+m4;c[1][1]=m1-m2+m3+m6;printf("\nAfter multiplication using \n");for(i=0;i<2;i++){printf("\n");for(j=0;j<2;j++)printf("%d\t",c[i][j]);}return 0; }

    Output:

    輸出:

    Enter the 4 elements of first matrix:5 6 1 7Enter the 4 element of second matrix:6 2 8 7The first matrix is5 61 7The second matrix is6 28 7After multiplication 78 5262 51

    Complexity: The time complexity is O(N2.8074).

    復(fù)雜度:時(shí)間復(fù)雜度為O(N 2.8074 ) 。

    翻譯自: https://www.includehelp.com/algorithms/strassen-matrix-multiplication.aspx

    總結(jié)

    以上是生活随笔為你收集整理的算法中的Strassen矩阵乘法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。