machine learning - Not getting correct value of cost function in neural network classifier with pre calculated weights. [Octave] -
i'm facing problem in programming assignment. formula calculating cost function neural network is:
in case, h 5000x10 matrix , y 5000x1 vector. i'm calculating using following code:
x = [ones(m, 1), x]; a2 = sigmoid(x * theta1'); a2new = [ones(m, 1), a2]; h = sigmoid(a2new * theta2'); %x matrix of training examples, theta1 , theta2 precalculated weights, a2 hidden layer. k = num_labels; % number of classes = 1:k; c = y==k; j = (-1/m)*((c' * log(h(:,i)))' + ((1-c)' * log(1-h(:,i)))'); end
the answer around 0.23 i'm getting 9. can tell me wrong in code?
for code, think should y == i
rather y==k
in for-loop.
for = 1:k; c = y==i; j = (-1/m)*((c' * log(h(:,i)))' + ((1-c)' * log(1-h(:,i)))'); end
and
second, way vectorize y
seems not correct, should (1:num_labels)' == y'
using vectorization implementation.
Comments
Post a Comment