def Evaluate(self, validation=True, collect_predictions=False):
    """Evaluate the model.
    Args:
      validation: If True, evaluate on the validation set,
        else evaluate on test set.
      collect_predictions: If True, collect the predictions.
    """
    step = 0
    stats = []
    if validation:
      stopcondition = self.ValidationStopCondition
      stop = stopcondition(step)
      if stop or self.validation_data_handler is None:
        return
      datagetter = self.GetValidationBatch
      prefix = 'V'
      stats_list = self.net.validation_stats
      num_batches = self.validation_data_handler.num_batches
    else:
      stopcondition = self.TestStopCondition
      stop = stopcondition(step)
      if stop or self.test_data_handler is None:
        return
      datagetter = self.GetTestBatch
      prefix = 'E'
      stats_list = self.net.test_stats
      num_batches = self.test_data_handler.num_batches
    if collect_predictions:
      output_layer = self.output_datalayer[0]
      collect_pos = 0
      batchsize = output_layer.batchsize
      numdims = output_layer.state.shape[0]
      predictions = np.zeros((batchsize * num_batches, numdims))
      targets = np.zeros(predictions.shape)
    while not stop:
      datagetter()
      losses = self.EvaluateOneBatch()
      if collect_predictions:
        predictions[collect_pos:collect_pos + batchsize] = \
            output_layer.state.asarray().T
        targets[collect_pos:collect_pos + batchsize] = \
            output_layer.data.asarray().T
        collect_pos += batchsize

      if stats:
        for loss, acc in zip(losses, stats):
          Accumulate(acc, loss)
      else:
        stats = losses
      step += 1
      stop = stopcondition(step)
    if collect_predictions and stats:
      predictions = predictions[:collect_pos]
      targets = targets[:collect_pos]
      MAP, prec50, MAP_list, prec50_list = self.ComputeScore(predictions, targets)
      stat = stats[0]
      stat.MAP = MAP
      stat.prec50 = prec50
      for m in MAP_list:
        stat.MAP_list.extend([m])
      for m in prec50_list:
        stat.prec50_list.extend([m])
    for stat in stats:
      sys.stdout.write(GetPerformanceStats(stat, prefix=prefix))
    stats_list.extend(stats)
Evaluate the model.
    Args:
      validation: If True, evaluate on the validation set,
        else evaluate on test set.
      collect_predictions: If True, collect the predictions.
    
deepnet/neuralnet.py