Matlab:在神经网络中使用交叉熵
Matlab: Use cross-entropy in 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);
那么如何在我的代码中使用交叉熵?
问题是 trainlm
仅适用于使用 Jacobian Matrix
的损失函数,如文档所述:
This function uses the Jacobian for calculations, which assumes that
performance is a mean or sum of squared errors. Therefore, networks
trained with this function must use either the mse or sse performance
function.
一种解决方案是使用其他训练算法,例如 trainrp
或 trainscg
。以下作品:
[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);
我正在尝试使用交叉熵实现 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);
那么如何在我的代码中使用交叉熵?
问题是 trainlm
仅适用于使用 Jacobian Matrix
的损失函数,如文档所述:
This function uses the Jacobian for calculations, which assumes that performance is a mean or sum of squared errors. Therefore, networks trained with this function must use either the mse or sse performance function.
一种解决方案是使用其他训练算法,例如 trainrp
或 trainscg
。以下作品:
[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);