Array indices must be positive integers or logical values, Neural Network Performances

1 回表示 (過去 30 日間)
Jingyuan Yao
Jingyuan Yao 2021 年 7 月 30 日
回答済み: Salman Ahmed 2021 年 8 月 4 日
Hi, I am trying to improve the neural network according to this documentation
% % Einleger_Binaer_Alle_inv_sortiert - input data.
% % Auslenkung_Alle_inv - target data.
%
x = Einleger_Binaer_Alle_inv_Sortiert;
t = Auslenkung_Alle_inv;
rng('default');
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainlm'; % nicht Levenberg-Marquardt backpropagation, da schneller
% Create a Fitting Network
% hiddenLayerSize = 10;
% network = fitnet(hiddenLayerSize,trainFcn);
% For More hidden Layers und Neurons
n = 3;
s = 10;
layerSizes = ones(1, n)*s; % Creating vector with layer sizes
network = fitnet(layerSizes, trainFcn);
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
network.input.processFcns = {'removeconstantrows','mapminmax'};
network.output.processFcns = {'removeconstantrows','mapminmax'};
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivision
network.divideFcn = 'divideind'; % Devide Data set into Test and Train
network.divideMode = 'sample'; % Divide up every sample
% network.divideParam.trainRatio = 100/100;
% network.divideParam.valRatio = 0/100;
% network.divideParam.testRatio = 0/100;
Q = 130;
trainInd =1:100;
valInd = [];
testInd =101:130;
[trainInd,valInd,testInd] = divideind(Q,trainInd,valInd,testInd); % Indizes für Test und TrainingsSet
% Validation: Patch15 + 18 --> Index 18 + Index 21 {"Patch15",-32.6529000000000,-86.0407000000000}
% Test: Vollbelegt --> Index 35 {"Vollbelegt01",-33.6531000000000,-89.8866000000000}
% net.divideFcn = 'divideind'; % Divide data according to index
% [trainInd,valInd,testInd] = divideind(36,[1:17, 19:20, 22:34, 36], [18, 21], 35);
% net.divideParam.trainInd = trainInd;
% net.divideParam.valInd = valInd;
% net.divideParam.testInd = testInd;
% Aktivierungsfunktion definieren
%net.layers{1}.transferfkn
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
network.performFcn = 'mse'; % Mean Squared Error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
network.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
% Train the Network
%[net,tr] = train(net,x,t);
%%Number of networks to train
numNN = 100;
network_array = cell(1, numNN);
for i = 1:numNN
fprintf('Training %d/%d\n', i, numNN)
network_array{i} = train(network, x, t,'CheckpointFile','MyCheckpoint','CheckpointDelay',120);
save 20212101_Workspace_NN_Torsion % Biegung und Torsion
end
save 20212101_Workspace_NN_Torsion
% Define Test Data, 101- 130
testdataset = t(101:130);
% Test the Network, but for more networks
errors = zeros (1, numNN);
perfs = zeros (1, numNN);
for i = 1:numNN
neti = network_array(i);
y2 = neti(testdataset);
perfs(i) = perform(network,t,y2);
errors(i) = gsubtract(t,y2);
save 20212101_Workspace_NN_Torsion
end
I trained 100 network and try to get their performance and errors. I extract the test data and it should be tested with the testdataset. It actually works.
But it always shows " Array indices must be positive integers or logical values" when it comes to code
y2 = neti(testdataset);
What could be the problem?
I appreciate any help!

回答 (1 件)

Salman Ahmed
Salman Ahmed 2021 年 8 月 4 日
Hi Jingyuan Yao,
From my understanding, you have made the following typo in your code,
Change it from :
neti = network_array(i);
to :
neti = network_array{i};
For more information, refer to the page access data in cell array.

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by