Speeding up dynamic programming code

조회 수: 2 (최근 30일)
Paolo Binetti
Paolo Binetti 2017년 6월 13일
Is there a way to speed up this piece of code implementing a dynamic programming algorithm?
% sample input
v = repmat('CGACAGCTACTCACTCAGTAGCCGCAGCGAGTGTCTTGACAATTCGGAGGGG', 1, 20);
w = repmat('TATACACATTCATGAATGAAAATTGACCTCCTACAGTTGTAGTGGTAGT', 1, 20);
n = numel(v);
m = numel(w);
s = zeros(n+1, m+1);
back = zeros(n, m);
for i = 1:n
temp = s(i, 1:end-1)+(v(i)==w);
for j = 1:m
[s(i+1, j+1), back(i, j)] = max([s(i, j+1) s(i+1, j) temp(j)]);
end
end
(Memory is also an issue when scaling up, due to the size of arrays "s" and "back", but I have found a way to reduce "s" to just two lines, and "back" could be expressed as uint8)

답변 (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