Info
Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.
can modify this code to be faster?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
hi all,
Please plaes I badly need help urgently. I built code of associative rules as prdiction algorithm. The code is working well when dataset small(less than 100 itration), but when be larger the code be very very bad in terms of running time, where the running time become 12 minuts for 800 itration .
The code is very important for me because it is part of my PhD work.May the code is evaluated with bad score by the committee because of running time
I hope find somebody can modify the code to be faster.
Thanks in advance
support_ant_cons(1,1)=struct('item',[0]);
f=dlmread('d:\matlab\r2011a\bin\new_movielens1\10m_mov\associative_rules\one_community\table_one_community.txt');
[p o]=size(f);r=1; B=1;
support_ant=sum(f); kkk=1;
for i=1:p
dd=1;
x=f(i,:);
%%find the items has no seen before for each user
for j=1:o
if x(j)==0
idx(dd)=j;
dd=dd+1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for g=1:length(idx)
j1=1;
for j=1:o
if f(i,j)==1
d1=0;
for k=1:p
if f(k,j)==1 & f(k,idx(g))==1
d1=d1+1;
end
end
d1;
support_ant_cons(i,j).item(g)=d1;
confidence1(g,j1)=(support_ant_cons(i,j).item(g)/support_ant(j));
confidence(j1)=(support_ant_cons(i,j).item(g)/support_ant(j));
j1=j1+1;
else
continue;
end
end
confidence_rule(i,g)=max(confidence(1:j1-1));
item(i,g)=idx(g);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N_top=5;
length(idx);
[recomm ind1]=sort(confidence_rule(i,:),'descend');
if length(idx)>=N_top
recom_list(i,1:N_top)=item(i,ind1(1:N_top));
eval_item=dlmread('d:\matlab\r2011a\bin\new_movielens1\10m_mov\eval_map.txt');
f1=dlmread('d:\matlab\r2011a\bin\new_movielens1\10m_mov\ratio80\total_final.txt');
[m n]=size(eval_item);
yy=f1(i,:);
yy=yy(yy~=0);
unique_x=unique(yy);
z=eval_item(i,:);
z=z(z~=0);
z=unique(z);
t=1;
evaluation=[];
for v=1:length(z)
a1=find(unique_x==z(v));
if isempty(a1)
evaluation(t)=z(v);
t=t+1;
end
end
if length(evaluation)>=1
k=1;
zzz(kkk)=i;
kkk=kkk+1;
h=1;
for v=1:18
b2=find(unique_x==v);
if isempty(b2)
relevant_item(i,h)=v;
h=h+1;
end
end
r1=relevant_item(i,:);
relevant_item_len=r1(r1~=0);
eval=evaluation;
eval=eval(eval~=0);
recom2=recom_list(i,:);
recom2=recom2(recom2~=0);
d=intersect(recom2,eval);
r=1;
for zz=1:length(recom2)
a1=find(d==recom2(zz));
if isempty(a1)
b(r)=recom2(zz);
r=r+1;
end
end
if r==1
b=[];
end
if t==1
c=[];
pc=0;
relv1=relevant_item(i,:);
relv1=relv1(relv1~=0);
recom1=recom_list(i,:);
recom1=recom1(recom1~=0);
[buf buf1]=intersect(relv1,recom1);
for m1=1:length(buf)
r1(buf1(m1)-pc)=[];
pc=pc+1;
end
a=r1(r1~=0);
else
xx=evaluation;
xx=xx(xx~=0);
xx=unique(xx);
r2=1;
for zz=1:length(xx)
a1=find(d==xx(zz));
if isempty(a1)
c(r2)=xx(zz);
r2=r2+1;
end
end
if r2==1
c=[];
end
pc=0;
relv=relevant_item(i,:);
relv=relv(relv~=0);
recom=recom_list(i,:);
recom=recom(recom~=0);
[buf buf1]=intersect(relv,recom);
for k=1:length(buf)
r1(buf1(k)-pc)=[];
pc=pc+1;
end
pc=0;
eval2=evaluation;
eval2=eval2(eval2~=0);
[buf0 buf2]=intersect(r1,eval2);
for zz=1:length(buf0)
r1(buf2(zz)-pc)=[];
pc=pc+1;
end
a=r1(r1~=0);
end
a=a(a~=0);
b=b(b~=0);
c=c(c~=0);
d=d(d~=0);
par_confusion(B,1)=length(a);
par_confusion(B,2)=length(b);
par_confusion(B,3)=length(c);
par_confusion(B,4)=length(d);
accuracy(B)=(length(a)+length(d))/(length(a)+length(b)+length(c)+length(d));
precis_recall(B,1)= length(d)/(length(b)+length(d));
precis_recall(B,2)=length(d)/(length(d)+length(c));
B=B+1;
clear b;
clear d;
clear c;
clear a;
else
'he has no evaluation'
end%%%%%%end of if evaluation
end %%%end if length(idx)
end %%%end for i
1 Kommentar
Antworten (1)
Image Analyst
am 8 Mai 2013
Why don't you use the "Run and time" tool on the Home tab to see what parts of your code are taking the longest?
3 Kommentare
Image Analyst
am 8 Mai 2013
Looks like alphabet soup to me. See if you can vectorize it somehow. I don't really have the time to dig into this code.
Diese Frage ist geschlossen.
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!