program takes long time to run
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
Robert Cumming
le 1 Nov 2011
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 commentaires
Plus de réponses (1)
Lulu
le 1 Nov 2011
If Nf is large, then try to vectorize FOR loop.
1 commentaire
Jan
le 1 Nov 2011
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.
Voir également
Catégories
En savoir plus sur Test and Measurement dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!