All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gov.sandia.cognition.learning.performance.AbstractSupervisedPerformanceEvaluator Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * File:                AbstractSupervisedErrorMeasure.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 *
 * Copyright September 27, 2007, Sandia Corporation.  Under the terms of Contract
 * DE-AC04-94AL85000, there is a non-exclusive license for use of this work by
 * or on behalf of the U.S. Government. Export of this program may require a
 * license from the United States Government. See CopyrightHistory.txt for
 * complete details.
 *
 *
 */

package gov.sandia.cognition.learning.performance;

import gov.sandia.cognition.learning.data.InputOutputPair;
import gov.sandia.cognition.evaluator.Evaluator;
import gov.sandia.cognition.learning.data.DatasetUtil;
import gov.sandia.cognition.learning.data.DefaultWeightedTargetEstimatePair;
import gov.sandia.cognition.learning.data.TargetEstimatePair;
import gov.sandia.cognition.util.AbstractCloneableSerializable;
import gov.sandia.cognition.util.Summarizer;
import java.util.ArrayList;
import java.util.Collection;

/**
 * The {@code AbstractSupervisedPerformanceEvaluator} class contains an 
 * abstract implementation of the {@code SupervisedPerformanceEvaluator} class.
 * It does the conversion of a dataset of input-target pairs to a set of
 * target-estimate pairs given the estimate returned by the evaluator whose
 * performance is being assessed.
 *
 * @param    The input type to evaluate.
 * @param    The type of the ground-truth targets (the labels).
 * @param    The type of estimate to evaluate.
 * @param    The output type of the performance evalautor.
 * @author  Justin Basilico
 * @since   2.0
 */
public abstract class AbstractSupervisedPerformanceEvaluator
    extends AbstractCloneableSerializable
    implements SupervisedPerformanceEvaluator,
    Summarizer, ResultType>
{

    /**
     * Creates a new AbstractSupervisedPerformanceEvaluator.
     */
    public AbstractSupervisedPerformanceEvaluator()
    {
        super();
    }

    /**
     * Evaluates the performance accuracy of the given estimates against the
     * given targets.
     *
     * @param evaluator Evaluator to generate estimates
     * @param  data The target-estimate pairs to use to evaluate performance.
     * @return The performance evaluation result.
     */
    public ResultType evaluatePerformance(
        final Evaluator evaluator,
        final Collection> data )
    {
        // Use the given evaluator to compute the Target-Estimate pairs for
        // the given data.
        final ArrayList> pairs =
            new ArrayList>( data.size() );

        for (InputOutputPair example : data)
        {
            final InputType input = example.getInput();
            final TargetType target = example.getOutput();
            final EstimateType estimate = evaluator.evaluate( input );
            final double weight = DatasetUtil.getWeight(example);
            pairs.add(DefaultWeightedTargetEstimatePair.create(target, estimate, weight));
        }

        // Evaluate the performance of the pairs.
        return this.evaluatePerformance( pairs );
    }

    public ResultType summarize(
        Collection> data )
    {
        return this.evaluatePerformance( data );
    }

    public abstract ResultType evaluatePerformance(
        Collection> data );

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy