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

gov.sandia.cognition.learning.function.scalar.VectorFunctionLinearDiscriminant Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * File:                VectorFunctionLinearDiscriminant.java
 * Authors:             Kevin R. Dixon
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry
 * 
 * Copyright Nov 30, 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.function.scalar;

import gov.sandia.cognition.learning.function.regression.AbstractRegressor;
import gov.sandia.cognition.evaluator.Evaluator;
import gov.sandia.cognition.math.matrix.Vector;
import gov.sandia.cognition.math.matrix.Vectorizable;
import gov.sandia.cognition.util.ObjectUtil;

/**
 * This class takes a function that maps a generic InputType to a Vector. We
 * then take the dot product of that Vector with a weight Vector to yield the
 * scalar output.  The parameters of this class are in the weight Vector.
 * 
 * @param  Must map this class onto a Vector
 * @author Kevin R. Dixon
 */
public class VectorFunctionLinearDiscriminant
    extends AbstractRegressor
    implements Vectorizable
{

    /**
     * Maps the input space to a Vector
     */
    private Evaluator vectorFunction;

    /**
     * The dot product of the discriminant with the output of the
     * vectorFunction is the output (scalar) value. Must have the
     * same dimensions as the outputDimensionality of vectorFunction.
     */
    private LinearDiscriminant discriminant;
    
    
    /** 
     * Creates a new instance of VectorFunctionLinearDiscriminant 
     * @param vectorFunction
     * Maps the input space to a Vector
     * @param discriminant
     * The dot product of the discriminant with the output of the
     * vectorFunction is the output (scalar) value. Must have the
     * same dimensions as the outputDimensionality of vectorFunction.
     */
    public VectorFunctionLinearDiscriminant(
        Evaluator vectorFunction,
        LinearDiscriminant discriminant )
    {
        this.setVectorFunction(vectorFunction);
        this.setDiscriminant(discriminant);
    }

    @Override
    public VectorFunctionLinearDiscriminant clone()
    {
        @SuppressWarnings("unchecked")
        VectorFunctionLinearDiscriminant clone =
            (VectorFunctionLinearDiscriminant) super.clone();
        clone.setVectorFunction(
            ObjectUtil.cloneSmart( this.getVectorFunction() ) );
        clone.setDiscriminant( ObjectUtil.cloneSafe( this.getDiscriminant() ) );
        return clone;
    }

    /**
     * Getter for discriminant
     * @return
     * The dot product of the discriminant with the output of the
     * vectorFunction is the output (scalar) value. Must have the
     * same dimensions as the outputDimensionality of vectorFunction.
     */
    public LinearDiscriminant getDiscriminant()
    {
        return this.discriminant;
    }

    /**
     * Setter for discriminant
     * @param discriminant
     * The dot product of the discriminant with the output of the
     * vectorFunction is the output (scalar) value. Must have the
     * same dimensions as the outputDimensionality of vectorFunction.
     */
    public void setDiscriminant(
        LinearDiscriminant discriminant )
    {        
        this.discriminant = discriminant;
    }

    /**
     * Getter for vectorFunction
     * @return
     * Maps the input space to a Vector
     */
    public Evaluator getVectorFunction()
    {
        return this.vectorFunction;
    }

    /**
     * Setter for vectorFunction
     * @param vectorFunction
     * Maps the input space to a Vector
     */
    public void setVectorFunction(
        Evaluator vectorFunction )
    {
        this.vectorFunction = vectorFunction;
    }

    @Override
    public double evaluateAsDouble(
        InputType input )
    {
        Vector vfOutput = this.getVectorFunction().evaluate(input);
        return this.getDiscriminant().evaluate(vfOutput);
    }

    public Vector convertToVector()
    {
        return this.getDiscriminant().convertToVector();
    }

    public void convertFromVector(
        Vector parameters )
    {
        this.getDiscriminant().convertFromVector(parameters);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy