views:

57

answers:

1

I used ffnew functions many times but when I am trying to create a simple feed forward network such that the input vector is P=[1;2;3;4] and the desired output is T=[1 ;0;0;1]. So i only have one sample input vector

The code is

net = newff(P,T,[4 1],{'tansig','tansig'});
net=train (net,P,T);

When I write the last line I got:

??? Error using ==> plus
Matrix dimensions must agree.

Error in ==> calcperf2 at 163
        N{i,ts} = N{i,ts} + Z{k};

Error in ==> trainlm at 253
[perf,El,trainV.Y,Ac,N,Zb,Zi,Zl] = calcperf2(net,X,trainV.Pd,trainV.Tl,trainV.Ai,Q,TS);

Error in ==> network.train at 216
  [net,tr] = feval(net.trainFcn,net,tr,trainV,valV,testV);
+1  A: 

Perhaps a simple example will help. Consider the famous XOR problem:

input = [0 0; 0 1; 1 0; 1 1]';               %'# each column is an input vector
ouputActual = [0 1 1 0];                     %#

net = newpr(input, ouputActual, 2);          %# 1 hidden layer with 2 neurons
net.divideFcn = '';                          %# use the entire input for training

net = init(net);                             %# init
[net,tr] = train(net, input, ouputActual);   %# train
outputPredicted = sim(net, input);           %# predict

[err,cm] = confusion(ouputActual,outputPredicted);

Note that I used NEWPR instead of NEWFF. The reason is that it uses a logistic function on the output (NEWFF does linear), which is more suited for classification tasks. If you use a 1-of-N target encoding, the output will be in the range [0,1] and can be interpreted as posterior probabilities for each class (NEWFF will not be restricted to [0,1])

Amro

related questions