2016-04-21 86 views
0

我正在嘗試使用交叉熵來實現RNN。下面是我的代碼:Matlab:在神經網絡中使用交叉熵

net = layrecnet(1:2,10); 
net.performFcn = 'crossentropy'; 
net.performParam.regularization = 0.1; 
net.performParam.normalization = 'none'; 
[Xs,Xi,Ai,Ts] = preparets(net, featureMatrix, labels); 
net = train(net,Xs,Ts,Xi,Ai); 
% view(net) 
Y = net(Xs,Xi,Ai); 
perf = perform(net,Y,Ts); 

performParam是從MATLAB的官方doc。但是,我執行後,我得到了一個警告說:

Warning: Performance function replaced with squared 
error performance. 
> In trainlm>formatNet (line 155) 
    In trainlm (line 65) 
    In nntraining.setup (line 14) 
    In network/train (line 335) 

即使我執行前饋網,我也得到了同樣的警告。以下是我的代碼。

[x,t] = simplefit_dataset; 
net = feedforwardnet(10); 
net.performFcn = 'crossentropy'; 
net.performParam.regularization = 0.1; 
net.performParam.normalization = 'none'; 
net = train(net,x,t); 
view(net) 
y = net(x); 
perf = perform(net,y,t); 

那麼我怎麼能在我的代碼中使用交叉熵呢?

+0

[請點擊此鏈接](http://ch.mathworks.com/matlabcentral/answers/261735-i-get-a-performance-function-replaced-with-squared-error-性能警告,當試圖設置c) – obchardon

+0

@obchardon我讀過,但沒有幫助。 – spacegoing

回答

1

的問題是trainlm僅適用於使用Jacobian Matrix損失函數爲筆賬:

該功能用來計算雅可比,它假設 性能是一個平均值或誤差平方和。因此,使用此功能訓練的網絡必須使用mse或sse性能 函數。

一種解決方案是使用其他訓練算法,如trainrptrainscg。以下工作:

[x,t] = simplefit_dataset; 
net = feedforwardnet(10); 
net.performFcn = 'crossentropy'; 
net.performParam.regularization = 0.1; 
net.performParam.normalization = 'none'; 
net.trainFcn = 'trainrp'; 
net = train(net,x,t); 
view(net) 
y = net(x); 
perf = perform(net,y,t);