我正在與matlab neural network toolbox玩弄,我遇到了一些我沒想到的事情。我的問題特別是沒有隱藏層的分類網絡,只有1個輸入和tansig傳輸函數。所以我希望這個分類器在一個由學習輸入權重和偏差定義的點上劃分一維數據集。首先,我認爲用於計算給定輸入x的輸出y的公式爲:其中w是輸入權重,b是偏差,y = f(x * w + b) 。計算網絡輸出的正確公式是什麼?Matlab神經網絡給出了意想不到的結果
我還希望將整個數據集翻譯一定的值(+77)會對偏差和/或權重產生很大影響。但似乎並非如此。爲什麼數據集的翻譯對偏差和體重沒有太大影響?
這是我的代碼:
% Generate data
p1 = randn(1, 1000);
t1(1:1000) = 1;
p2 = 3 + randn(1, 1000);
t2(1:1000) = -1;
% view data
figure, hist([p1', p2'], 100)
P = [p1 p2];
T = [t1 t2];
% train network without hidden layer
net1 = newff(P, T, [], {'tansig'}, 'trainlm');
[net1,tr] = train(net1, P, T);
% display weight and bias
w = net1.IW{1,1};
b = net1.b{1,1};
disp(w) % -6.8971
disp(b) % -0.2280
% make label decision
class_correct = 0;
outputs = net1(P);
for i = 1:length(outputs)
% choose between -1 and 1
if outputs(i) > 0
outputs(i) = 1;
else
outputs(i) = -1;
end
% compare
if T(i) == outputs(i)
class_correct = class_correct + 1;
end
end
% Calculate the correct classification rate (CCR)
CCR = (class_correct * 100)/length(outputs);
fprintf('CCR: %f \n', CCR);
% plot the errors
errors = gsubtract(T, outputs);
figure, plot(errors)
% I expect these to be equal and near 1
net1(0) % 0.9521
tansig(0*w + b) % -0.4680
% I expect these to be equal and near -1
net1(4) % -0.9991
tansig(4*w + b) % -1
% translate the dataset by +77
P2 = P + 77;
% train network without hidden layer
net2 = newff(P2, T, [], {'tansig'}, 'trainlm');
[net2,tr] = train(net2, P2, T);
% display weight and bias
w2 = net2.IW{1,1};
b2 = net2.b{1,1};
disp(w2) % -5.1132
disp(b2) % -0.1556
我生成與具有不同的平均的正態分佈由2羣的人工數據集。我用直方圖繪製這些種羣,並用它訓練網絡。 我計算了正確的分類率,它是整個數據集的正確分類實例的百分比。這在92%左右,所以我知道分類器的工作原理。
但是,我期望net1(x)和tansig(x * w + b)給出相同的輸出,但事實並非如此。計算我的訓練網絡輸出的正確公式是什麼?
而且我預計net1和net2有不同的權重和/或偏差,因爲net2是在訓練net1的數據集的翻譯版本(+77)上訓練的。爲什麼數據集的翻譯對偏差和體重沒有太大影響?
如果您對神經網絡感興趣,可以考慮加入機器學習網站:http://area51.stackexchange.com/proposals/41738/machine-learning – travisbartley