view costFunction.m @ 5:a4c4da8f4ac0

Style fixes
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Tue, 08 Nov 2011 00:56:18 -0500
parents 8b902ada47e9
children 141d81a2acf5
line wrap: on
line source

function [J, grad] = costFunction(theta, X, y)
##COSTFUNCTION Compute cost and gradient for logistic regression
##   J = COSTFUNCTION(theta, X, y) computes the cost of using theta as the
##   parameter for logistic regression and the gradient of the cost
##   w.r.t. to the parameters.

  m = length (y);

  ## h_theta(x)
  ht = sigmoid (X*theta); 

  J = -sum (y.*log (ht) + (1 - y).*log (1 - ht))/m
  grad = X'*(ht - y)/m;

endfunction