“Index Exceeds Matrix Dimensions” neural network f

2019-07-21 18:37发布

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?

3条回答
Viruses.
2楼-- · 2019-07-21 19:06

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-07-21 19:13

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);
查看更多
叛逆
4楼-- · 2019-07-21 19:16

I solved it by:

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

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

查看更多
登录 后发表回答