Parfor: Variable indexed in different ways.

6 visualizzazioni (ultimi 30 giorni)
I want to parallelize the following for loop but the I have the following problem: In a parfor loop variable 'perf' is indexed in different ways
The problem is in the 3rd line from the bottom because I index in a different way the matrix perf.
How can I avoid this problem?
NET = cell(5,11);
TR = cell(5,11);
ave_perfs = zeros(1,11);
perf = zeros(5,11);
profile on;
parfor j = 1:11
for bin = 1:5
processed_train_Ext = load([ExtensionTrainPath,'/',Features{j},'/','train',num2str(bin),'_processed_Ext'];
processed_train_Flx = load([FlexionTrainPath,'/',Features{j},'/','train',num2str(bin),'_processed_Flx']);
processed_test_Ext = load([ExtensionTestPath,'/',Features{j},'/','test',num2str(bin),'_processed_Ext']);
processed_test_Flx = load([FlexionTestPath,'/',Features{j},'/','test',num2str(bin),'_processed_Flx']);
% concatenating the training data
train_data = [processed_train_Ext.finalMatrix(:,1:end-1); processed_train_Flx.finalMatrix(:,1:end-1)];
true_train_labels = [processed_train_Ext.finalMatrix(:,end); processed_train_Flx.finalMatrix(:,end)];
%concatenating the test data
test_data = [processed_test_Ext.finalMatrix(:,1:end-1) ; processed_test_Flx.finalMatrix(:,1:end-1)];
true_test_labels = [processed_test_Ext.finalMatrix(:,end); processed_test_Flx.finalMatrix(:,end)];
%fit network
net = fitnet(5);
net.divideParam.trainRatio = 0.85;
net.divideParam.valRatio = 0.15;
net.divideParam.testRatio = 0.0;
% train and validate train data
[net, tr] = train(net,train_data',true_train_labels','useParallel','yes');
NET{bin,j} = net;
TR{bin,j} = tr;
% test newly trained network with test data
outputs = NET{bin,j}(test_data','useParallel','yes');
% calculate accuracy on the test data
perf(bin,j) = 1 - mse(net, true_test_labels, outputs);
toc
beep on; beep;
end
% calculate averages of the errors
ave_perfs(1,j) = sum(perf(:,j))/5;
end
  5 Commenti
OCDER
OCDER il 29 Set 2017
I actually didn't know what the issue was until I tried your solution, which did the trick for me.
Greg
Greg il 29 Set 2017
Ahh, fair enough. My MATLAB machine is not my internet machine, so I'm rarely able to test the poster's code or my own suggestions.
I'm glad we got it solved and an accepted answer. Thanks for the assist.

Accedi per commentare.

Risposta accettata

Greg
Greg il 28 Set 2017
Try replacing this code (inside the loop):
% calculate averages of the errors
ave_perfs(1,j) = sum(perf(:,j))/5;
With this code (outside the parfor):
% calculate averages of the errors
ave_perfs = mean(perf,1);
Then you could even remove the pre-allocation of ave_perfs at the top.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by