2011-05-11 206 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]'; 

現在,它的工作原理。