필터 지우기
필터 지우기

How to optimize the multiplication of large matrices in Matlab?

조회 수: 11 (최근 30일)
John
John 2013년 3월 8일
댓글: Ken 2016년 11월 18일
I have 2 matrices A, B, and vector C that I need to multiply. They are fairly large.
Matrix A = 10000x10000
Matrix B = 10000x10000
Vector C = 10000x1
If I perform A*B*C, this takes a long time so I used sparse function which collapses the matrices/vectors by removing large number of zeros then I convert it back to a full matrix.
full(sparse(A)*sparse(B)*sparse(C))
It's faster but I was wondering if there are more efficient techniques for multiplying them together. Would it be better to write for loops?
Secondly, some of the elements in my matrix have values close to zero so I can replace these with zeroes before converting them to sparse matrices. What's the best way to do this?

채택된 답변

James Tursa
James Tursa 2013년 3월 8일
Force the matrix-vector multipy to happen first. E.g.,
A*(B*C)
  댓글 수: 2
John
John 2013년 3월 8일
Dude, this improved the performance. Thanks!!!
Ken
Ken 2016년 11월 18일
it works really well! surprised!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sean de Wolski
Sean de Wolski 2013년 3월 8일
I doubt you'll be able to get anything faster than the highly optimized BLAS libraries that MATLAB uses to perform matrix arithmetic. The only thing I've heard of that might be faster is mtimesx on the FEX and even that, I've never reproduced.

per isakson
per isakson 2013년 3월 8일
편집: per isakson 2013년 3월 8일
Your second question:
A( A < small_number ) = 0;
or better
A( abs(A) < small_number ) = 0;
  댓글 수: 2
John
John 2013년 3월 8일
편집: John 2013년 3월 8일
Thanks, does the abs(A) make it faster or more efficient?
Sean de Wolski
Sean de Wolski 2013년 3월 8일
it makes it so that -25 does not become 0.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by