100 likes | 460 Views
Matrix Multiplication. Winograd Multiplication. V=(v 1 ,v 2 ,v 3 ,v 4 ) W=(w 1 ,w 2 ,w 3 ,w 4 ) V · W=v 1 w 1 +v 2 w 2 +v 3 w 3 +v 4 w 4 V · W=(v 1 +w 2 )(v 2 +w 1 ) + (v 3 +w 4 )(v 4 +w 3 ) -v 1 v 2 -v 3 v 4 -w 1 w 2 -w 3 w 4. Generalization. Compute Once, Use many times.
E N D
Winograd Multiplication • V=(v1,v2,v3,v4) • W=(w1,w2,w3,w4) • V·W=v1w1+v2w2+v3w3+v4w4 • V·W=(v1+w2)(v2+w1) + (v3+w4)(v4+w3) -v1v2-v3v4-w1w2-w3w4
Generalization Compute Once, Use many times
Analysis • Ordinary Matrix Multiply, n3 • Winograd’s Matrix Multiply, (n3/2)+n2 • Additions, n3-n2, v.s. (3/2)n3+2n2-2n • Lower Bound, Best known is n2 • Best known Upper Bound and Best Known Lower Bound are not the same
Two By Two Multiplication • c1,1=a1,1b1,1+a1,2b2,1 • c1,2=a1,1b1,2+a1,2b2,2 • c2,1=a2,1b1,1+a2,2b2,1 • c2,2=a2,1b1,2+a2,2b2,2
2x2 Works for Matrices • C1,1=A1,1B1,1+A1,2B2,1 • C1,2=A1,1B1,2+A1,2B2,2 • C2,1=A2,1B1,1+A2,2B2,1 • C2,2=A2,1B1,2+A2,2B2,2 A1,1 A1,2 B1,1 B1,2 C1,1 C1,2 ´ = A2,1 A2,2 B2,1 B2,2 C2,1 C2,2
Divide and Conquer? • Assume matrices of size 2n´2n • Multiplications: M(n) = 8M(n/2), M(1)=8 • Additions: A(n) = 8A(n/2)+n2 • M(n) = 8lg n = nlg 8 = n3 • Additions are also Q(n3), but point is moot • Can we reduce the 8 multiplications in the base equations
Strassen’s Equations • x1=(a1,1+a2,2)(b1,1+b2,2) • x2=(a2,1+a2,2) b1,1 • x3=a1,1(b1,2-b2,2) • x4=a2,2(b2,1-b1,1) • x5=(a1,1+a1,2) b2,2 • x6=(a2,1-a1,1)(b1,1+b1,2) • x7=(a1,2-a2,2)(b2,1+b2,2)
Using The Equations • c1,1 = x1 + x4 - x5 + x7 • c1,2 = x3 + x5 • c2,1 = x2 + x4 • c2,2 = x1 + x3 - x2 + x6
Analysis of Strassen • Only 7 multiplications are used • Will work with matrices, because associative property is not used • Multiplications: M(n) = 7M(n/2), M(1) = 7 • Additions: A(n) = 7A(n/2)+18(n2/4) • M(n) = 7lg n = nlg 7 = n2.81 • Additions are also Q(n2.81) • First algorithm to break the n3 “barrier”