'Accumulate the metrics calculated locally for this mini-batch.
Args:
predictions: A numpy matrix containing the outputs of the model.
Dimensions are \'batch\' x \'num_classes\'.
labels: A numpy matrix containing the ground truth labels.
Dimensions are \'batch\' x \'num_classes\'.
loss: A numpy array containing the loss for each sample.
Returns:
dictionary: A dictionary storing the metrics for the mini-batch.
Raises:
ValueError: An error occurred when the shape of predictions and actuals
does not match.'

def accumulate(self, predictions, labels, loss):

    batch_size = labels.shape[0]
    mean_hit_at_one = calculate_hit_at_one(predictions, labels)
    mean_perr = calculate_precision_at_equal_recall_rate(predictions, labels)
    mean_loss = numpy.mean(loss)
    (sparse_predictions, sparse_labels, num_positives) = top_k_by_class(predictions, labels, self.top_k)
    self.map_calculator.accumulate(sparse_predictions, sparse_labels, num_positives)
    self.global_ap_calculator.accumulate(flatten(sparse_predictions), flatten(sparse_labels), sum(num_positives))
    self.num_examples += batch_size
    self.sum_hit_at_one += (mean_hit_at_one * batch_size)
    self.sum_perr += (mean_perr * batch_size)
    self.sum_loss += (mean_loss * batch_size)
    return {'hit_at_one': mean_hit_at_one, 'perr': mean_perr, 'loss': mean_loss}
