2011-05-11 209 views
0

我使用一个简单的XOR输入和输出数据集来训练一个神经网络,然后再尝试任何困难但由于某种原因它不起作用。MATLAB神经网络

请问有人请解释我做错了吗? 这是我的代码:

%user specified values 
hidden_neurons = 3; 
epochs = 10000; 

t_input = [1 1; 1 0; 0 1; 0 0]; 
t_output = [1; 0; 0; 1]; 
te_input = [1 1; 1 0; 0 1; 0 0]; 

net = newff(t_input, t_output, 1); 
net = init(net); 
net = train(net, t_input, t_output); 
net.trainParam.show = 50; 
net.trainParam.lr = 0.25; 
net.trainParam.epochs = epochs; 
net.trainParam.goal = 1e-5; 
net = train(net, t_input, t_output); 
out = sim(net, te_input); 

这是我的错误消息:

???错误地使用==> network.train在145个目标网络的大小不正确。矩阵必须有2列。

错误在==> smallNN at 11 net = train(net,t_input,t_output);

回答

1

你必须有你的列上的样品,而不是行(像所有世界NN软件做的),所以更改数据集生成线:

t_input = [1 1; 1 0; 0 1; 0 0]'; 
t_output = [1; 0; 0; 1]'; 
te_input = [1 1; 1 0; 0 1; 0 0]'; 

现在,它的工作原理。