【问题标题】:Matlab: Use cross-entropy in neural networkMatlab:在神经网络中使用交叉熵
【发布时间】:2016-04-21 06:28:33
【问题描述】:

我正在尝试使用交叉熵来实现 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) 

即使我执行前馈网络,我也会收到同样的警告。以下是我的代码。

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

那么如何在我的代码中使用交叉熵呢?

【问题讨论】:

标签: matlab recurrent-neural-network


【解决方案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);

【讨论】:

    猜你喜欢
    • 2017-06-01
    • 1970-01-01
    • 2021-03-26
    • 2015-12-03
    • 2011-08-23
    • 2011-03-26
    • 2016-04-15
    • 2017-12-24
    • 2014-01-15
    相关资源
    最近更新 更多