@staticmethod
def evaluate(tproblem, phase):
    """Evaluates the performance of the current state of the model
        of the testproblem instance.
        Has to be called in the beggining of every epoch within the
        training method. Returns the losses and accuracies.

        Args:
            tproblem (testproblem): The testproblem instance to evaluate
            phase (str): The phase of the evaluation. Must be one of 'TRAIN', 'VALID' or 'TEST'
        Returns:
            float: The loss of the current state.
            float: The accuracy of the current state.

        """
    if phase == 'TEST':
        tproblem.test_init_op()
        msg = 'TEST:'
    elif phase == 'TRAIN':
        tproblem.train_eval_init_op()
        msg = 'TRAIN:'
    elif phase == 'VALID':
        tproblem.valid_init_op()
        msg = 'VALID:'
    loss = 0.0
    accuracy = 0.0
    batchCount = 0.0
    while True:
        try:
            batch_loss, batch_accuracy = tproblem.get_batch_loss_and_accuracy()
            batchCount += 1.0
            loss += batch_loss.item()
            accuracy += batch_accuracy
        except StopIteration:
            break
    loss /= batchCount
    accuracy /= batchCount
    if accuracy != 0.0:
        print('{0:s} loss {1:g}, acc {2:f}'.format(msg, loss, accuracy))
    else:
        print('{0:s} loss {1:g}'.format(msg, loss))
    return loss, accuracy
