필터 지우기
필터 지우기

Fast computation of an equation.

조회 수: 1 (최근 30일)
David Ernesto Caro
David Ernesto Caro 2019년 9월 9일
댓글: David Ernesto Caro 2019년 9월 11일
Given two matrices:
We want a the fastest way to compute the vector \phi.... (j=1 to m).
Is there a way to use parallel computation, any trick?
  댓글 수: 8
David Ernesto Caro
David Ernesto Caro 2019년 9월 9일
Thanks Walter! Is working.
Bruno Luong
Bruno Luong 2019년 9월 10일
편집: Bruno Luong 2019년 9월 10일
what are typically m,n and s?
If you have X as matrix the best method might be different, see my answer bellow.

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

채택된 답변

Bruno Luong
Bruno Luong 2019년 9월 10일
편집: Bruno Luong 2019년 9월 10일
The efficientcy of the bellow method depend on m, n, s
% Generate dummy test data
m = 1000;
n = 1000;
s = 1000;
W = rand(m,n);
V = rand(m,n);
X = rand(n,s);
% Walter method
tic
Xp = permute(X,[3 1 2]);
Z1 = sum((Xp-W).*(V-Xp),2);
Z1 = reshape(Z1,[m s]).';
toc % Elapsed time is 2.816333 seconds.
% My new method
tic
Z2 = -sum(X.^2,1)+(W+V)*X-sum(W.*V,2);
Z2 = Z2.';
toc % Elapsed time is 0.040274 seconds.
% Check correctness
norm(Z1-Z2,'fro')/norm(Z1,'fro') % 4.6622e-15

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by