I keep getting the error "Index exceeds array bounds".
4 views (last 30 days)
Show older comments
% INITIALIZE THE NEURAL NETWORK PROBLEM %
% inputs for the neural net(AND gate example== 2 inputs && 4 samples)
inputs = inputs';
% targets for the neural net
targets = TargetNormalized';
% number of neurons
n = 4;
% create a neural network
net = feedforwardnet(n);
% configure the neural network for this dataset
net = configure(net, inputs, targets);
% get the normal NN weights and bias
getwb(net)
% error MSE normal NN
error = targets - net(inputs);
calc = mean(error.^2)/mean(var(targets',1))
% create handle to the MSE_TEST function, that
% calculates MSE
h = @(x) NMSE(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.
% PLEASE NOTE: For a feed-forward network
% with n hidden neurons, 3n+n+1 quantities are required
% in the weights and biases column vector.
% a. n for the input weights=(features*n)=2*n
% b. n for the input biases=(n bias)=n
% c. n for the output weights=(n weights)=n
% d. 1 for the output bias=(1 bias)=1
% running the particle swarm optimization algorithm with desired options
[x, err_ga] = pso(h, 2*n+n+n+1)
net = setwb(net, x');
% get the PSO optimized NN weights and bias
getwb(net)
% error MSE PSO optimized NN
error = targets - net(inputs);
calc = mean(error.^2)/mean(var(targets',1))
% Index exceeds array bounds.
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 NMSE (line 7)
net = setwb(net, wb);
Error in main>@(x)NMSE(x,net,inputs,targets)
Error in pso (line 67)
particle(i).Cost=CostFunction(particle(i).Position);
Error in main (line 43)
[x, err_ga] = pso(h, 2*n+n+n+1)
Im keep geeting this error, no solution
0 Comments
Answers (0)
See Also
Categories
Find more on Particle Swarm in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!