crossentropy_snn.m

来自「神经网络的工具箱, 神经网络的工具箱,」· M 代码 · 共 40 行

M
40
字号
function f = crossentropy_snn(a, t)%CROSSENTROPY_SNN Cross entropy error.%%  Syntax%%   f = crossentropy_snn(y, t)%%     y - output%     t - target%     f - cross entropy error%if isstr(a)   switch lower(a)     case 'deriv',	  f = 'dcrossentropy_snn';     case '2deriv',          f = 'd2crossentropy_snn';     case 'inv',          f = 'invcrossentropy_snn';     otherwise,	  error('Unrecognized code.')   end   returnendTINY = 1e-8;a(find(a>=1.0)) = 1.0 - TINY;a(find(a<=-1.0)) = -1.0 + TINY;f = zeros(size(a));indices = find(t==1);f(indices) = (1+a(indices)).^(-2);indices = find(t==-1);f(indices) = (1-a(indices)).^(-2);indices = find((t~=1) & (t~=-1));f(indices) = 0.5 * ( (1+t(indices)).*log((1+t(indices))./(1+a(indices))) ...                   + (1-t(indices)).*log((1-t(indices))./(1-a(indices))) );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?