'Compute loss and also deriv w.r.t to it if asked for.
Compute the loss function. Targets should be in self.data, predictions
should be in self.state.
Args:
get_deriv: If True, compute the derivative w.r.t the loss function and put
it in self.deriv.'

def GetLoss(self, get_deriv=False):

    perf = deepnet_pb2.Metrics()
    perf.MergeFrom(self.proto.performance_stats)
    perf.count = self.batchsize
    tiny = self.tiny
    temp = self.batchsize_temp
    if (self.loss_function == deepnet_pb2.Layer.SQUARED_LOSS):
        if get_deriv:
            target = self.deriv
        else:
            target = self.statesize
        if self.hyperparams.normalize_error:
            self.data.sum(axis=0, target=temp)
            temp.add(self.tiny)
            self.data.div_by_row(temp, target=target)
            self.state.div_by_row(self.NN, target=self.expanded_batch)
            target.subtract(self.expanded_batch)
        else:
            self.data.sum(axis=0, target=temp)
            temp.add(self.tiny)
            self.state.div_by_row(temp, target=target)
            target.subtract(self.data)
        error = (target.euclid_norm() ** 2)
        perf.error = error
    else:
        raise Exception('Unknown    loss    function    for    Replicated    Softmax    units.')
    return perf
