program takes long time to run

조회 수: 8 (최근 30일)
FIR
FIR 2011년 11월 1일
I have a code below,which takes long time to run,can u tell how to process please....
Gout is my input which contains 990 rows and 4 colomns of data(990*4)
Ng=Gout
hidden_neurons =6;
epochs = 100;
wait_l = epochs*Nf;
wait_i = 0;
%h = waitbar(0,'Training Neural Network');
for i = 1:Nf
st = (i-1)*round(size(Traindata,1)/Nf)+1;
en = i*round(size(Traindata,1)/Nf);
if en>size(Traindata,1)
en=size(Traindata,1);
end
train_inp = [Traindata(1:st-1,:);Traindata(en+1:end,:)];
train_out = [Trainlabel(1:st-1,:);Trainlabel(en+1:end,:)];
test_inp = Traindata(st:en,:);
[Predicted,wait_i] = Neural1(hidden_neurons, epochs, train_inp, train_out, test_inp, wait_l, wait_i);
Training_error_NN(i,:) = sum(abs(Predicted-Trainlabel(st:en,:)));
Training_acc_NN(i,:) = accuracy(Predicted,Trainlabel(st:en,:));
end
% close(h);
pause(1);
%wait_i = 0;
%h = waitbar(0,'Testing Neural Network');
for i = 1:Nf
st = (i-1)*round(size(Testdata,1)/Nf)+1;
en = i*round(size(Testdata,1)/Nf);
if en>size(Testdata,1)
en=size(Testdata,1);
end
train_inp = Traindata;
train_out = Trainlabel;
test_inp = Testdata(st:en,:);
[Predicted,wait_i] = Neural1(hidden_neurons, epochs, train_inp, train_out, test_inp, wait_l, wait_i);
Testing_error_NN(i) = sum(abs(Predicted-Testlabel(st:en,:)));
Testing_acc_NN(i) = accuracy(Predicted,Testlabel(st:en,:));
(Testing_acc_NN')
(Testing_error_NN')
result=[fc1 Testing_acc_NN' Testing_error_NN']
end
% close(h);
pause(1);
  댓글 수: 2
Naz
Naz 2011년 11월 1일
It takes long time to read too
FIR
FIR 2011년 11월 1일
Naz provide some suggestion

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

채택된 답변

Robert Cumming
Robert Cumming 2011년 11월 1일
you have 2 "pause" commands in the code - any idea how many times they are called?
Have you used the profiler?
profile on % then run your code
profile viewer
That will show you were your code is taking the most time.

추가 답변 (1개)

Lulu
Lulu 2011년 11월 1일
If Nf is large, then try to vectorize FOR loop.
  댓글 수: 1
Jan
Jan 2011년 11월 1일
I wouldn't do this. The creation of large temporary arrays is usually more time-consuming than the accleration by the vectorization. The vectorization is helpful, if the data are available as arrays already.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by