“Index Exceeds Matrix Dimensions” neural network function error

佐手、 提交于 2019-12-13 16:28:08

问题


I've got two datasets, which I load from a CSV file, and split them into X and T:

X (3x5000) double
T (1x5000) double

I'm trying to configure this function, but I can't

http://www.mathworks.co.uk/help/toolbox/nnet/ref/layrecnet.html

X has three features and 5000 examples. T has one feature and 5000 examples. For an example the target is feature 1 20 steps ahead. So basically X(1,21) == T(1).

[X,T] = simpleseries_dataset;

This works perfectly, in this case, I have 1x100, 1x100.

If I use my own data set, however, I get this:

X = data(:,1:3)';
T = data(:,4)';
net = layrecnet(1:2,10);
[Xs,Xi,Ai,Ts] = preparets(net,X,T);

??? Index exceeds matrix dimensions.

Error in ==> preparets at 273
  ti = tt(:,FBS+((1-net.numLayerDelays):0));

I don't understand, what am I doing wrong?

UPDATE

I've noticed that my data set is T (1x5000) double while the example dataset is T (1x100) cell. What's the difference between double and cell?


回答1:


I solved it by:

X = num2cell(X);
T = num2cell(T);

I have no idea why; it must be MATLAB syntax...




回答2:


You can solve it by:

  P = con2seq(p);
   T = con2seq(t);

.....% for example

p=(1 2;3 4;5 6);
t=(3;7;11);

.....%now

P = con2seq(p);
T = con2seq(t);
net = elmannet(1:2,12);
[Xs,Xi,Ai,Ts] = preparets(net,P,T);
net = train(net,Xs,Ts,Xi,Ai);
view(net)
Y = net(Xs,Xi,Ai);
perf = perform(net,Ts,Y);



回答3:


To clarify "(...)it must be MATLAB syntax...":

The problem here is the conversion from double to cell arrays. Matlab does not do this automatically since a cell can contain any type of value as mentioned here: http://www.mathworks.com/help/matlab/matlab_prog/what-is-a-cell-array.html

So, as mentioned in your answer, you can either convert your double arrays to cell arrays using num2cell() or you can allocate X and T as cell arrays from the very beginning using cell() and then copying your double values into them. This explicit type cast is necessary because preparets expects cell arrays as input, much like many of the plot functions in the ANN package.



来源:https://stackoverflow.com/questions/10080079/index-exceeds-matrix-dimensions-neural-network-function-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!