3.3 「Stanford Algorithms」Strassen's Subcubic Matrix Multiplication Algorithm - Part 1

In this video, we'll apply the divide and conquer algorithm design paradigm to the problem of multiplying matrices.

This will culminate in the study of Strassen's Matrix Multiplication Algorithm.

And this is a super cool algorithm for two reasons.

First of all, Strassen's Algorithm is completely non trivial.

It is totally non-obvious, very clever.

Not at all clear how Strassen ever came up with it.

The second cool feature, is, it's for such a fundamental problem.

So computers, as long as they've been in use, from the time they were invented, up'til today, a lot of their cycles are spent multiplying matrics, 'cause it just come up all the time in important applications.

So let me first just make sure we're all clear on what the, what the problem is of.

Multiplying two matrices.

So, we're gonna be interested in three matrices, X, Y, and Z.

They're all gonna, I'm gonna assume they all have the same dimensions, N by N.

The ideas we'll talk about are also relevant for multiplying non square matrices, but we're not gonna discuss it in this video.

The entries in these matrices, you know, you could think of it as whatever you want.

Maybe they're integers, maybe they're rationals, maybe they're from some [inaudible] field.

It depends on the application.

But the point is, they're just entries that we can add and multiply.

So how is it that you take two N by N matrices, X and Y, and multiply them producing a new N by N matrix, Z? Well, recall that the IJ entry of Z, that means the entry in the Ith row and Jth column, is simply the dot product of the Ith row of X with the Jth column of Y.

So if IJ was this red square, this [inaudible] over in the Z matrix, that would be derived from the corresponding row of the X matrix, and the corresponding column of the Y matrix.

And recall what I mean by dot product.

That just means you take the products of the individual components, and then add up the results.

So ultimately, the ZIJ entry boils down to a sum over N things, where each of the constituent products is just the XIK entry.

The [inaudible] of the matrix X with the KJ entry, of the matrix Y, where your K is ranging from one to N.

So that's how ZIJ is defined for a given pair of indices, I and J.

One thing to note is where we often use N to denote the input size, here we're using N to note the dimension of each of these matricies.

The input size is not N.

The input size is quite a bit bigger than N.

Specifically, each of these are N by N matricies and contain N squared entries.

So since presumably we have to read the input which has size and square.

Which happens to produce the output that also has size and squared.

The best we can really hope for [inaudible] is multiplication hour with the running time n squared.

So the question is how close when we get to it.

Before we talk about algorithms for matrix multiplication, let me just make sure we're all crystal clear on exactly what the problem is.

So let's just actually spell out what would be the result of multiplying two different, two bytes of matrices.

So we can.

[inaudible] 21 generic 2x2 matricies by just giving the first one entries A, B, C, and D for these four entries could all be anything.

And then we're multiplying by a second 2x2 matrix, let's call it entries E, F, G, and H.

Now, what's the result of multiplying these, where again, it's going to be a 2x2 matrix for each entry, it's just the corresponding dot product of the relevant row of the first matrix and column of the second matrix.

So to get the upper left entry.

You take the doc product of the upper row of the first matrix and the first column of the left column of the second matrix.

So, that results in.

Ae plus BG.

To get the upper right entry, we take the dot product of the top row of the left matrix with the right column of the second matrix.

So that gives us AF+BH.

And then filling in the other entries the same way, we get CE+DG and DF+DH.

You know, so that's multiplying two matrices, and we've already discussed the definition in general.

Now, suppose you had to write a program to actually compute to the result of multiplying two N by N matrices.

One natural way to do that would just be to return to the definition and which defines each of the N squared entries in the Z matrix as a suitable sum of products of [inaudible] entries of the X and Y matrices.

So on the next quiz, I'd like you to.

Figure out what exactly would be the running time of that algorithm as a function of the matrix dimension N where as usual we count the addition or multiplication of two individual entries as a constant time operation.


在本视频中,我们将应用分而治之算法设计范例来解决矩阵相乘的问题。

这将在Strassen矩阵乘法算法的研究中达到高潮。

这是一个超酷的算法,有两个原因。

首先,斯特拉森算法是完全不平凡的。

这是完全不明显的,非常聪明。

完全不清楚Strassen是怎么想出来的。

第二个很酷的功能是针对这样一个基本问题。

因此,从发明以来一直使用到今天的计算机,直到今天,它们的许多周期都花在乘以矩阵上,因为它在重要的应用程序中一直存在。

因此,首先让我确保我们都清楚问题的根源。

将两个矩阵相乘。

因此,我们将对三个矩阵X,Y和Z感兴趣。

它们都是,我假设它们都具有相同的尺寸,N乘N。

我们将要讨论的想法也与非平方矩阵的乘积相关,但是我们不会在本视频中讨论。

您知道,这些矩阵中的条目可以随心所欲。

也许它们是整数,也许是理性的,也许它们来自某些[听不清]领域。

这取决于应用程序。

但关键是,它们只是我们可以相加和相乘的条目。

那么,如何取两个N×N矩阵X和Y,然后将它们相乘以产生一个新的N×N矩阵Z?好吧,回想一下Z的IJ条目,这意味着第I行和第J列中的条目只是X的第I行与Y的第J列的点积。

因此,如果IJ是这个红色正方形,则Z矩阵中的[听不清]将从X矩阵的相应行和Y矩阵的相应列派生。

并记得我所说的点积。

这只是意味着您要获取各个组件的产品,然后将结果相加。

因此,最终,ZIJ条目归结为N个事物的总和,其中每个构成产品只是XIK条目。

矩阵X的[音频不清晰]和KJ项,矩阵Y的K范围为1到N。

因此,这就是为给定索引对I和J定义ZIJ的方式。

需要注意的一件事是,我们经常使用N来表示输入大小,这里我们使用N来表示每个矩阵的维数。

输入大小不是N。

输入大小比N大很多。

具体而言,它们中的每一个都是N×N矩阵,并包含N个平方项。

因此,既然我们大概必须读取具有大小和平方的输入。

碰巧产生的输出也具有大小和平方。

我们真正希望[听不清]的最佳是运行时间为n平方的乘法小时。

所以问题是当我们接近它时有多近。

在我们讨论矩阵乘法的算法之前,让我先确保我们对问题到底是什么一清二楚。

因此,让我们实际说明将两个不同的两个字节矩阵相乘的结果。

所以我们可以。

[听不清] 21个2x2通用矩阵,只需为这四个条目指定第一个条目A,B,C和D,就可以成为任何东西。

然后我们乘以第二个2x2矩阵,我们将其称为条目E,F,G和H。

现在,将它们相乘的结果是什么,再次,每个条目将是一个2x2矩阵,它只是第一个矩阵的相关行和第二个矩阵的列的对应点积。

因此,获得左上角的条目。

您将获得第一个矩阵的上一行和第二个矩阵的左列的第一列的doc乘积。

因此,结果。

Ae加BG。

要获得右上角的条目,我们将左矩阵的顶行与第二个矩阵的右列的点积相乘。

这样就给了我们AF + BH。

然后以相同的方式填写其他条目,我们得到CE + DG和DF + DH。

您知道,所以将两个矩阵相乘,我们已经在一般性地讨论了该定义。

现在,假设您必须编写一个程序来实际计算两个N乘以N矩阵的结果。

一种自然的方法是返回定义,并将Z矩阵中N个平方项定义为X和Y矩阵[听不清]项的乘积之和。

因此,在下一个测验中,我希望您能参加。

弄清楚该算法的运行时间确切地取决于矩阵维数N的函数,在通常情况下,我们将两个单独条目的加法或乘法算作一个恒定时间操作。


Strassen's Subcubic Matrix Multiplication Algorithm - Question 1

What is the straightforward running time of the iterative algorithm for matrix multiplication?

A. 𝜃(𝑛log(𝑛))

B. 𝜃(𝑛^2)

C. 𝜃(𝑛^3)

D. 𝜃(𝑛^4)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,132评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,802评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,566评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,858评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,867评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,695评论 1 282
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,064评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,705评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,915评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,677评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,796评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,432评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,041评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,992评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,223评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,185评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,535评论 2 343