program takes long time to run
1 回表示 (過去 30 日間)
古いコメントを表示
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);
採用された回答
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.
0 件のコメント
その他の回答 (1 件)
Lulu
2011 年 11 月 1 日
If Nf is large, then try to vectorize FOR loop.
1 件のコメント
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!