我不断收到错误“索引超出数组范围”

时间:2020-06-04 05:34:52

标签: matlab optimization neural-network nonlinear-optimization particle-swarm

有一些问题,我的输入是30 * 27,输出是1 * 30,但这 代码出现了一些问题。不断收到错误索引超出了Matlab自己的代码文件中的数组范围,输入矩阵为27x30 double

 % 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)


'''

请帮助

  1. 编码 采样

0 个答案:

没有答案