Error index exceeds matrix dimensions why? Matlab 2016a
Mostrar comentarios más antiguos
input = 4*54 double target = 1*54 double *******************
% INITIALIZE THE NEURAL NETWORK PROBLEM\ %
% inputs for the neural net
inputs =input;
% targets for the neural net
targets =target;
% number of neurons
n = 4;
% create a neural network
net = feedforwardnet(n);
% configure the neural network for this dataset
net = configure(net, inputs, targets);
% create handle to the MSE_TEST function, that
% calculates MSE
h = @(x) mse_test(x, net, inputs, targets);
% Setting the Genetic Algorithms tolerance for
% minimum change in fitness function before
% terminating algorithm to 1e-8 and displaying
% each iteration's results.
ga_opts = gaoptimset('TolFun',1e-8,'MutationFcn', {@mutationuniform, 0.2}, ...
'CrossoverFraction',0.6,'PopulationSize',10,'display','iter');
%
% PLEASE NOTE: For a feed-forward network
% with n neurons, 3n+1 quantities are required
% in the weights and biases column vector.
%
% a. n for the input weights
% b. n for the input biases
% c. n for the output weights
% d. 1 for the output bias
% running the genetic algorithm with desired options
[x_ga_opt, err_ga] = ga(h, 3*n+1, ga_opts);
%
% codefunction mse_calc = mse_test(x, net, inputs, targets);
% 'x' contains the weights and biases vector
% in row vector form as passed to it by the
% genetic algorithm. This must be transposed
% when being set as the weights and biases
% vector for the network.
% To set the weights and biases vector to the
% one given as input
net = setwb(net, x');
% To evaluate the ouputs based on the given
% weights and biases vector
y = net(inputs);
% Calculating the mean squared error
mse_calc = sum((y-targets).^2)/length(y);
end
*****************************************
>> Weight
Index exceeds matrix dimensions.
Error in separatewb (line 34)
iw{i,j} = reshape(wb(hints.iwInd{i,j}),...
Error in setwb (line 23)
[b,IW,LW] = separatewb(net,wb,hints);
Error in mse_test (line 9)
net = setwb(net, x');
Error in Weight>@(x)mse_test(x,net,inputs,targets)
Error in createAnonymousFcn>@(x)fcn(x,FcnArgs{:}) (line 11)
fcn_handle = @(x) fcn(x,FcnArgs{:});
Error in makeState (line 47)
firstMemberScore = FitnessFcn(state.Population(initScoreProvided+1,:));
Error in gaunc (line 40)
state = makeState(GenomeLength,FitnessFcn,Iterate,output.problemtype,options);
Error in ga (line 371)
[x,fval,exitFlag,output,population,scores] = gaunc(FitnessFcn,nvars, ...
Error in Weight (line 30)
[x_ga_opt, err_ga] = ga(h, 3*n+1, ga_opts);
Caused by:
Failure in initial user-supplied fitness function evaluation. GA cannot continue.
>>
2 comentarios
Marc Youcef
el 21 de Jun. de 2017
Hello, I have exact similar error without being able to understand where it could come from ... Did you find any way to go through?
Mani S
el 28 de Mzo. de 2022
Have you got the answer Marc Youcef
Respuestas (1)
Greg Heath
el 22 de Jun. de 2017
0 votos
The Support group example is only for single inputs.
See my version for multiple inputs.
Hope this helps
Thank you for formally accepting my answer
Greg
1 comentario
zain yousaf
el 6 de Jun. de 2020
sir i cannot find your version for multiple i/o please give us the link.
Categorías
Más información sobre Define Shallow Neural Network Architectures en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!