I'm going through Andrew Ng's course on machine learning and am currently writing a forward propagation code in MATLAB/Octave that solves this cost function:
Currently, I have wrote it in a for loop form like this:
for i= 1:m
for j= 1:num_labels
J = J + log(ht(j,i))*y(j,i) + log(1-ht(j,i))*(1-y(j,i));
end
end
J = -J/m;
And that gets the job done. However, I would like to simplify this code, as I always feel a little "dirty" using for loops in MATLAB when I feel I could be using a vectorized form. But the for loops seem natural since there are 2 summations.