算法中的Strassen矩陣乘法

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年概述了如何用蠻力算法找到兩個2 * 2維矩陣的乘法。 但是通過使用分而治之技術,兩個矩陣相乘的整體復雜度降低了。 如果以乘法數略有增加為代價執行乘法,則會通過減少總數來實現。

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.

為了將兩個2 * 2維矩陣相乘, 斯特拉森使用了一些公式,其中有七個乘法和十八個加法,減法,在蠻力算法中,有八個乘法和四個加法。 Strassen公式的效用由矩陣階數n達到無窮大時的漸近優越性表示。 讓我們考慮兩個矩陣ABn * n維,其中n是2的冪。 可以觀察到,我們可以包含來自AB及其乘積C的四個n / 2 * n / 2個子矩陣。 CAB的合成矩陣。

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

There are some procedures:

有一些過程:

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

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

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

    使用前面的一組公式進行2 * 2矩陣乘法。

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

    在這八個乘法和四個加法中,執行減法。

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

    合并兩個矩陣的結果以找到最終乘積或最終矩陣。

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

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

Strassen的矩陣乘法中,總共有七個乘法和四個加減法。

    1.	D1 =  (a11 + a22) (b11 + b22)
2.	D2 =  (a21 + a22).b11
3.	D3 =  (b12 – b22).a11
4.	D4 =  (b21 – b11).a22
5.	D5 =  (a11 + a12).b22
6.	D6 =  (a21 – a11) . (b11 + b12)
7.	D7 =  (a12 – a22) . (b21 + b22)
C11 = d1 + d4 – d5 + d7
C12 = d3 + d5
C21 = d2 + d4
C22 = 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 compute
C = a * b is a conventional matrix.
Else
Partition 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+d5
d2+d4           d1+d3-d2-d6  
end if
return (C)
end.

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

#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 7
Enter the 4 element of second matrix:
6 2 8 7
The first matrix  is
5       6
1       7
The second matrix is
6       2
8      7
After multiplication 
78         52
62         51

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

復雜度:時間復雜度為O(N 2.8074 )

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/378934.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/378934.shtml
英文地址,請注明出處:http://en.pswp.cn/news/378934.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

零拷貝、mmap、sendfile

目錄零拷貝mmapsendFile總結零拷貝 要了解零拷貝&#xff0c;首先得先了解一下傳統 IO 的執行流程&#xff0c;這里舉個例子&#xff0c;通過傳統的 IO 進行網絡傳輸來傳輸一個文件。 先上一張圖&#xff0c;這張圖就代表了傳統 IO 傳輸文件的流程。 讀取文件的時候&#xf…

網頁服務器和mysql服務器_實現Web服務器之間使用同一個MYSQL和相同的網頁配置文件的方法...

實現Web服務器之間使用同一個MYSQL和相同的網頁配置文件的方法發布時間&#xff1a;2020-04-15 16:42:41來源&#xff1a;億速云閱讀&#xff1a;133作者&#xff1a;三月欄目&#xff1a;數據庫億速云負載均衡(Cloud Load Balancer)是對多臺云服務器進行流量分發的服務。億速云…

傳128GB版iPad4售價為799/929美元

外媒9to5mac報道&#xff0c;蘋果將推出一款升級版iPad4&#xff0c;外觀和iPad 4相同&#xff0c;還是黑白兩色的&#xff0c;只加入了新的SKU。 據報道&#xff0c;這款升級版iPad4還有128GB版&#xff0c;隨著這條消息傳出&#xff0c;不久關于128GB版iPad4的售價信息也傳出…

(西工程-金花)小米路由器連接哆點設置WiFi保姆式教程

小米路由器連接電源,用根網線一端插入寢室的網口處,另一端插入小米路由器的WAN口手機或者電腦連接WiFi,我這里是通過手機瀏覽器打開192.168.31.1進入無線路由器管理頁面進行配置小米路由器&#xff0c;配置WiFi的一些基本參數,例如:WiFi名稱,密碼之類的信息 進入無線路由器管理…

基于MINA框架快速開發網絡應用程序

1&#xff0e;MINA框架簡介 Netty、Mina、Cindy都是不錯的NIO開源框架&#xff0c;后兩者都是在Netty的基礎上演化出來的。MINA(Multipurpose Infrastructure for Network Applications)是用于開發高性能和高可用性的網絡應用程序的基礎框架。通過使用MINA框架可以可以省下處理…

Python中@staticmethod和@classmethod之間的區別

classmethod裝飾器 (The classmethod Decorator) The classmethod decorator is an inbuilt function decorator that gets evaluated after the function is defined. The result of the evaluation shadows the function definition. The classmethods first argument is alw…

go 聲明二維數組_一篇文章了解Go語言中數組Arrays的使用內幕

概述與其他編程語言類似&#xff0c;Go語言也有數組array。Go語言中&#xff0c;數組的行為和其他語言沒有什么不同.Go語言中還有一個叫做切片slice的東西&#xff0c;它就像是對數組的引用。在本文中&#xff0c;我們將只研究數組。定義數組是同一類型元素的連續集合&#xff…

ffmpeg 使用ffplay 進行 hls 拉流 分析 1

ffmpeg 使用 ffplay 進行 hls 拉流 分析 1 從使用ffplay 調用 http://192.168.1.100:8080/live/livestream.m3u8 開始&#xff0c;進入到ffmpeg 的分析使用的協議選擇相應的解復用器的步驟。 其他協議或者文件方式的使用ffplay也是這個步驟流程的。 目錄&#xff1a;一、流程圖…

搜狗輸入法輸出特殊符號快捷鍵

https://www.petefreitag.com/cheatsheets/ascii-codes/ 參考上個編碼網站大全 詳細步驟為&#xff1a;alt長按 &#xff0b; 編碼數字 例如&#xff1a;平方的編碼為178-----長按alt178 即可&#xff0c;178是數字一個一個挨個按即可 常用的特殊符號如下&#xff1a; 平方&…

echo 12345678 | base64 產生的結果跟12345678真正的base64編碼不對

echo "12345678" | base64 產生的結果跟"12345678"真正的base64編碼不對 弄了好久才搞清楚&#xff0c;echo 命令是帶換行符的&#xff0c;改成echo -n "12345678" | base64就沒問題了轉載于:https://www.cnblogs.com/senix/archive/2013/01/30/…

[BuildRelease Management]CC.NET架構

一 CC.NET的操作流程 1) 等待Trigger的喚醒&#xff1b; 2&#xff09;從Source Control System查詢上次build以后的修改列表&#xff1b; 3&#xff09;如果任何修改被發現或是Trigger觸發類型為 force the build &#xff1a; 3.1&#xff09;為build產生一個label number&a…

python 入門到實踐期末考試常出現的考試內容_Python編程入門到實踐—列表篇(一)...

一、列表是什么&#xff1f;列表由一系列按特定順序排列的元素組成。可以創建包含字母表中所有字母、數字0-9或所有家庭成員姓名的列表&#xff1b;也可以將任何東西加入列表中&#xff0c;其中的元素之間可以沒有任何關系。列表通常包含多個元素&#xff0c;給列表指定一個表示…

c#中將集合寫入文本_在C#中將記錄插入MySQL數據庫

c#中將集合寫入文本In the last tutorial (how to connect with MySQL database in C#?), we learned about making the connection with MySQL database in C#. Here, in this tutorial, we will learn how to insert the records in MySQL database in C#? 在上一教程( 如何…

read/fread write/fwrite 的區別

fread就是通過read來實現的&#xff0c;fread是C語言的庫&#xff0c;而read是系統調用。 差別在read每次讀的數據是調用者要求的大小&#xff0c;比如調用者要求讀取10個字節數據&#xff0c;read就會從內核緩沖區&#xff08;操作系統開辟的一段空間用來存儲磁盤上的數據&am…

如何在子網中訪問上層網絡的計算機文件夾

場景 公司路由器A&#xff0c;直接接外部網線&#xff0c;內部ip192.168.11.1&#xff0c;lan口又接了路由器A1&#xff0c;IP為192.168.11.2&#xff0c;A1的lan端口接了一臺電腦A&#xff0c;Ip為192.168.0.2&#xff0c;接了另外一個路由A2&#xff0c;Ip為192.168.11.3&…

基于Web的套打方案分析

應用web化&#xff0c;不論對開發商&#xff0c;還是對用戶來說&#xff0c;實在是一種很經濟的選擇&#xff0c;因為基于web的應用&#xff0c;客戶端的規則很簡單&#xff0c;容易學習&#xff0c;容易維護&#xff0c;容易發布。但對程序員來說&#xff0c;因為瀏覽器的局限…

day1-Linux操作系統基礎

該專欄所有內容筆記均來自傳智播客培訓班 1.什么是操作系統&#xff08;operate system OS&#xff09; 小議&#xff1a;承上啟下作用&#xff0c;向下可以控制硬件&#xff0c;向上能夠支持軟件的運行。一個可以控制硬件的軟件。 小明找小紅聊天&#xff0c;小明打開QQ&…

關閉瀏覽器 清空session_跨境網絡小知識之Session

跨境小伙伴們大家好&#xff0c;上一篇為大家介紹了Cookie&#xff0c;今天就為大家介紹下連接cookie的另一端Session&#xff0c;交互過程中&#xff0c;二者缺一不可。與Cookie相對&#xff0c;Session是存儲在服務端的&#xff0c;他們之間是通過一個叫做sessionID的東東建立…

我和乘子交替方向法admm_找到最大和交替子序列

我和乘子交替方向法admmProblem statement: 問題陳述&#xff1a; Given a sequence of numbers, you have to find the maximum sum alternating subsequence and print the value. A sequence is an alternating sequence when it will be maintain like (increasing) ->…

Dojo學習筆記(一):Hello Dojo!

歡迎來到Dojo世界&#xff01;在這篇文章中你將會學習到如何加載Dojo以及探索Dojo的一些核心功能。你還會了解Dojo的基于AMD的模塊架構&#xff0c;探索如何加載額外的模塊來增加功能到您的Web站點或應用程序&#xff0c;并找出在出錯的時如何得到幫助。讓我們開始吧 開始學習D…