Demo entry 6677214

cost

   

Submitted by anonymous on Dec 03, 2017 at 08:04
Language: Matlab. Code size: 230 Bytes.

function [J, grad] = costfunction(W,X,y)
%损失函数和梯度
m=length(y);%训练集的大小
%初始化返回值
J=0.0;
grad=zeros(size(W));
J=1/m*(-y'*log(sigmoid(X*W))-(1-y')*(log(1-sigmoid(X*W))));
%vpa(J,100);
grad=(1./m).*(X'*(sigmoid(X*W)-y))

end

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).