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

gov.sandia.cognition.learning.function.categorization.ScalarFunctionToBinaryCategorizerAdapter Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * File:                ScalarFunctionToBinaryCategorizer.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 * 
 * Copyright April 07, 2009, 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.function.categorization;

import gov.sandia.cognition.evaluator.Evaluator;
import gov.sandia.cognition.util.ObjectUtil;

/**
 * Adapts a scalar function to be a categorizer using a threshold.
 * 
 * @param  Input to the discriminant function.
 * @author  Justin Basilico
 * @since   3.0
 */
public class ScalarFunctionToBinaryCategorizerAdapter
    extends AbstractThresholdBinaryCategorizer
{

    /** The scalar evaluator. */
    protected Evaluator evaluator;

    /**
     * Creates a new {@code ScalarFunctionToBinaryCategorizerAdapter}.
     */
    public ScalarFunctionToBinaryCategorizerAdapter()
    {
        this(null);
    }

    /**
     * Creates a new {@code ScalarFunctionToBinaryCategorizerAdapter} with the
     * given evaluator and a default threshold of 0.0.
     *
     * @param   evaluator
     *      The scalar function to adapt.
     */
    public ScalarFunctionToBinaryCategorizerAdapter(
        final Evaluator evaluator)
    {
        this(evaluator, DEFAULT_THRESHOLD);
    }

    /**
     * Creates a new {@code ScalarFunctionToBinaryCategorizerAdapter} with the
     * given evaluator and threshold.
     *
     * @param   evaluator
     *      The scalar function to adapt.
     * @param   threshold
     *      The threshold to use.
     */
    public ScalarFunctionToBinaryCategorizerAdapter(
        final Evaluator evaluator,
        final double threshold)
    {
        super(threshold);

        this.setEvaluator(evaluator);
    }

    @Override
    @SuppressWarnings("unchecked")
    public ScalarFunctionToBinaryCategorizerAdapter clone()
    {
        ScalarFunctionToBinaryCategorizerAdapter clone =
            (ScalarFunctionToBinaryCategorizerAdapter) super.clone();

        clone.setEvaluator( ObjectUtil.cloneSmart(this.getEvaluator()) );
        return clone;
    }

    @Override
    protected double evaluateWithoutThreshold(
        InputType input)
    {
        return this.getEvaluator().evaluate(input);
    }

    /**
     * Gets the scalar function that the adapter wraps.
     *
     * @return
     *      The scalar function.
     */
    public Evaluator getEvaluator()
    {
        return this.evaluator;
    }

    /**
     * Sets the scalar function that the adapter wraps.
     *
     * @param   evaluator
     *      The scalar function.
     */
    public void setEvaluator(
        final Evaluator evaluator)
    {
        this.evaluator = evaluator;
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy