Strassen 矩阵乘法算法

发布于 2024-08-15 03:13:04 字数 123 浏览 4 评论 0原文

有人能以直观的方式解释斯特拉森的矩阵乘法算法吗?我已经阅读了(好吧,试图阅读)书中和维基中的解释,但它没有点击楼上。网络上任何使用大量英语而不是正式符号等的链接也会有所帮助。是否有任何类比可以帮助我从头开始构建这个算法而无需记住它?

Can someone please explain strassen's algorithm for matrix multiplication in an intuitive way? I've gone through (well, tried to go through) the explanation in the book and wiki but it's not clicking upstairs. Any links on the web that use a lot of English rather than formal notation etc. would be helpful, too. Are there any analogies which might help me build this algorithm from scratch without having to memorize it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

为你拒绝所有暧昧 2024-08-22 03:13:04

考虑将两个 2x2 矩阵相乘,如下所示:

A B * E F = AE+BG AF+BH
C D   G H   CE+DG CF+DH

计算右侧的明显方法就是进行 8 次乘法和 4 次加法。但想象乘法比加法昂贵得多,因此我们希望尽可能减少乘法的次数。施特拉森使用一种技巧来计算右侧,减少一次乘法,增加大量加法(以及一些减法)。

以下是 7 次乘法:

M1 = (A + D) * (E + H) = AE + AH + DE + DH
M2 = (A + B) * H = AH + BH
M3 = (C + D) * E = CE + DE
M4 = A * (F - H) = AF - AH
M5 = D * (G - E) = DG - DE
M6 = (C - A) * (E + F) = CE + CF - AE - AF
M7 = (B - D) * (G + H) = BG + BH - DG - DH

因此,要计算 AE+BG,请从 M1+M7(这为我们提供 AE 和 BG 项)开始,然后添加/减去其他一些 Ms,直到剩下 AE+BG。奇迹般的是,M 的选择使得 M1+M7-M2+M5 起作用。与所需的其他 3 个结果相同。

现在要意识到这不仅适用于 2x2 矩阵,而且适用于 A..H 是子矩阵的任何(偶数)大小的矩阵。

Consider multiplying two 2x2 matrices, as follows:

A B * E F = AE+BG AF+BH
C D   G H   CE+DG CF+DH

The obvious way to compute the right side is just to do the 8 multiplies and 4 additions. But imagine multiplies are a lot more expensive than additions, so we want to reduce the number of multiplications if at all possible. Strassen uses a trick to compute the right hand side with one less multiply and a lot more additions (and some subtractions).

Here are the 7 multiplies:

M1 = (A + D) * (E + H) = AE + AH + DE + DH
M2 = (A + B) * H = AH + BH
M3 = (C + D) * E = CE + DE
M4 = A * (F - H) = AF - AH
M5 = D * (G - E) = DG - DE
M6 = (C - A) * (E + F) = CE + CF - AE - AF
M7 = (B - D) * (G + H) = BG + BH - DG - DH

So to compute AE+BG, start with M1+M7 (which gets us the AE and BG terms), then add/subtract some of the other Ms until AE+BG is all we are left with. Miraculously, the M's are chosen so that M1+M7-M2+M5 works. Same with the other 3 results required.

Now just realize this works not just for 2x2 matrices, but for any (even) sized matrices where the A..H are submatrices.

长发绾君心 2024-08-22 03:13:04

在我看来,您需要了解 3 个想法:

  1. 您可以将矩阵拆分为多个块,然后像对数字矩阵一样对生成的块矩阵进行操作。特别是,您可以将两个这样的块矩阵相乘(当然,只要一个矩阵中的块行数与另一个中的块列数相匹配),并得到与原始数字矩阵相乘时相同的结果。

  2. 表达 2x2 块矩阵乘法结果所需的块具有足够的公因数,可以用比原始公式所暗示的更少的乘法来计算它们。这是托尼的回答中描述的技巧。

  3. 递归。

Strassen算法只是上述算法的一个应用。要理解其复杂性的分析,你需要阅读 Ronald Graham 的《具体数学》, Donald Knuth 和 Oren Patashnik 或类似的书。

In my opinion there are 3 ideas that you need to get:

  1. You can split a matrix into blocks and operate on the resulting matrix of blocks like you would on a matrix of numbers. In particular you can multiply two such block matrices (of course as long as the number of block rows in one matches the number of block columns in the other) and get the same result as you would when multiplying original matrices of numbers.

  2. The blocks necessary to express the result of 2x2 block matrix multiplication have enough common factors to allow computing them in fewer multiplications than the original formula implies. This is the trick described in Tony's answer.

  3. Recursion.

Strassen algorithm is just an application of the above. To understand the analysis of its complexity, you need to read "Concrete Mathematics" by Ronald Graham, Donald Knuth, and Oren Patashnik or a similar book.

陌生 2024-08-22 03:13:04

快速浏览了一下维基百科,在我看来,该算法稍微减少了重新排列方程所需的乘法次数。

这是一个类比。 x*x + 5*x + 6 有多少次乘法?两个,对吧? (x+2)(x+3) 中有多少次乘法?一,对吗?但他们的表情是一样的!

请注意,我并不期望这能提供对算法的深入理解,只是一种直观的方式,让您可以了解算法如何可能导致计算复杂性的提高。

Took a quick look at the Wikipedia and it appears to me that this algorithm is a slight reduction in the number of multiplications required by rearranging the equations.

Here's an analogy. How many multiplications in x*x + 5*x + 6? Two, right? How many multiplications in (x+2)(x+3)? One, right? But they're the same expression!

Note, I do not expect this to provide a deep understanding of the algorithm, just an intuitive way in which you can understand how the algorithm can possibly lead to an improvement in calculation complexity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文