フィルターのクリア

Performance of cell matrix in object

1 回表示 (過去 30 日間)
Yingke
Yingke 2012 年 2 月 16 日
Dear All. I am improving the efficiency of our prototype now.
There is an object(named 'D') contains a big cell matrix (named 'tran') and some other stuff. This cell matrix has many rows but only 2 columns (tran = cell(N,2))which I used to define the transition and weight of an automata (like a graph), so the number of rows are determined by the number of states in that automata. Each element in 'tran' is a sparse matrix, say (n,m).
There is a function 'func_m' which is called frequently. In 'func_m', the cell matrix 'tran' is updated. It works like this:
local_copy_tran = d.tran; %%%%% local_copy_tran = update(local_copy_tran); %%%%% d.tran = local_copy_tran;
I found that, directly cope with D.tran without local_copy is quite slow.
With the help of profiler, I found the last line 'd.tran = local_copy_tran;' is quite expensive.
Further more, there is a loop in the main update function, in that loop, get element from 'local_copy_tran' and update that is quite fast. However, the same operation becomes slow outside of that loop.
So, could you please give me some suggestion? Thanks a lot in advance.
-------------------------------------------------------------
In case that I didn't explain that clearly, the summary of profiler is attached below. The first column is time consumed, the 2nd one is the number of calls, the 3rd the line no.
0.04 3609 21 FrequencyTransitionMatrix = dffa.FrequencyTransitionMatrix;
0.03 3609 22 Predecessor = dffa.m_Predecessor;
0.03 3609 23 FinalStateFrequency = dffa.FinalStateFrequency;
24
0.01 3609 25 tp = Predecessor(q_b);
0.02 3609 26 tm = FrequencyTransitionMatrix{tp,1};
0.05 3609 27 [q,i] = find(tm == q_b);
28 %%%
0.02 3609 29 tm(q,i) = q_r;
*31.62 3609 30 FrequencyTransitionMatrix{tp,1} = tm;*
2.29 3609 35 Predecessor(q_b) = Predecessor(q_r);
36
< 0.01 3609 37 red = q_r;
0.05 3609 38 blue = q_b;
39
0.12 3609 40 while ~isempty(blue)
0.15 92350 41 qr = red(1);
0.07 92350 42 qb = blue(1);
0.66 92350 43 red = red(2:end);
0.60 92350 44 blue = blue(2:end);
45
2.29 92350 46 FinalStateFrequency(qr) = FinalStateFrequency(qr) + FinalStateFrequency(qb);
47 %Predecessor = dffa.m_Predecessor;
48
0.38 92350 49 mat = FrequencyTransitionMatrix(qr,:); % {qr,1} and {qr,2} is slower than (qr,:) {1} {2};
0.20 92350 50 tran_r = mat{1};
0.20 92350 51 freq_r = mat{2};
52
0.22 92350 53 mat = FrequencyTransitionMatrix(qb,:);
0.16 92350 54 tran_b = mat{1};
0.15 92350 55 freq_b = mat{2};
56
1.63 92350 57 same_tran = find(freq_r~=0 & freq_b~=0);
1.61 92350 58 diff_tran = find(freq_r==0 & freq_b~=0); % only qb's transition
59
60 % dffa.FrequencyTransitionMatrix{qr,2}(same_tran) = freq_r(same_tran) + freq_b(same_tran);
0.69 92350 61 FrequencyTransitionMatrix{qr,2} = freq_r + freq_b;
62
0.28 92350 63 tmp = tran_r(same_tran);
0.49 92350 64 tmp = nonzeros(tmp);
0.86 92350 65 red = [red,tmp'];
0.29 92350 66 tmp = tran_b(same_tran);
0.46 92350 67 tmp = nonzeros(tmp);
0.70 92350 68 blue = [blue,tmp'];
69
70 %tran_r(diff_tran) = tran_b(diff_tran);
71 %FrequencyTransitionMatrix(qr,:) = {tran_r,freq_r};
72
0.57 92350 73 FrequencyTransitionMatrix{qr,1}(diff_tran) = tran_b(diff_tran);
74
0.22 92350 75 if ~isempty(diff_tran)
0.06 20996 76 tmp = tran_b(diff_tran);
0.09 20996 77 tmp = tmp(tmp>0);
0.07 20996 78 if isempty(tmp)
0.09 15454 79 continue;
80 end
< 0.01 5542 81 Predecessor(tmp) = qr;
< 0.01 5542 82 end
0.54 76896 83 end
84
0.44 3609 85 dffa.m_Predecessor = Predecessor;
*66.17 3609 86 dffa.FrequencyTransitionMatrix = FrequencyTransitionMatrix;*
0.48 3609 87 dffa.FinalStateFrequency = FinalStateFrequency;
0.06 3609 88 end

回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by