Here is one implementation of the loss_func function in MATLAB that computes the empirical loss given the predicted target values t_hat and the true target values t:
main.m447 chars16 linesIn the above implementation, we first compute the element-wise squared error between the predicted and true target values using the error variable. Next, we compute the mean of error to obtain the empirical loss, which is returned by the function.
This implementation uses vectorized computation, which can be more efficient than computing the loss in a loop over individual samples.
gistlibby LogSnag