Matlab:在神经网络中使用交叉熵

时间:2016-04-21 06:28:33

标签: matlab recurrent-neural-network

我正在尝试使用交叉熵实现RNN。以下是我的代码:

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) 

即使我执行feedforwardnet,我也得到了相同的警告。以下是我的代码。

[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);

那我怎么能在代码中使用交叉熵呢?

1 个答案:

答案 0 :(得分: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);