/*
 *    PredictionManager.java
 *    Copyright (C) 2012-2013 Aristotle University of Thessaloniki, Greece
 */
package dbn;

import dbn.classifier.neural.DBLearner;
import mulan.classifier.MultiLabelLearnerBase;
import mulan.data.MultiLabelInstances;
import mulan.evaluation.*;

/**
 * A control class that manages the prediction task. It contains only one method
 * that manages the prediction.
 *
 * @author Evripidis Gkanias
 */
public class PredictionManager {
    
    /**
     * Takes as parameters the learned classifier and a dataset, sets up the
     * {@link Evaluator}, predicts the labels for the specific dataset and prints
     * the measures. <br />
     * Throws a {@link NullPointerException} when a parameter has not been set or the
     * dataset is empty.
     * 
     * @param learner the trained {@link DBLearner} classifier
     * @param testData the test dataset
     * @return the duration of the prediction and evaluation in milliseconds
     * @throws NullPointerException
     */
    public long TestData(MultiLabelLearnerBase learner, MultiLabelInstances testData) throws Exception {
        if (learner == null)
            throw new NullPointerException("Learner is not setted!");
        if (testData == null)
            throw new NullPointerException("Testing dataset is not setted!");
        if (testData.getNumInstances() <= 0 || testData.getNumLabels() <= 0)
            throw new NullPointerException("Testing dataset is empty!");
        
        Evaluator evaluator = new Evaluator();
        
        long start = System.currentTimeMillis();
        try {
            Evaluation evaluation = evaluator.evaluate(learner, testData.clone());
            System.out.println(evaluation.toString());
        } catch (Exception ex) {
            System.err.println("Testing data error: " + ex.toString());
        }
        return System.currentTimeMillis() - start;
    }
}
