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

gov.sandia.cognition.learning.algorithm.perceptron.AbstractKernelizableBinaryCategorizerOnlineLearner Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
/*
 * File:                AbstractKernelizableBinaryCategorizerOnlineLearner.java
 * Authors:             Justin Basilico
 * Company:             Sandia National Laboratories
 * Project:             Cognitive Foundry Learning Core
 * 
 * Copyright April 04, 2011, 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.
 *
 */

package gov.sandia.cognition.learning.algorithm.perceptron;

import gov.sandia.cognition.learning.algorithm.perceptron.kernel.KernelBinaryCategorizerOnlineLearnerAdapter;
import gov.sandia.cognition.learning.algorithm.SupervisedBatchAndIncrementalLearner;
import gov.sandia.cognition.learning.data.InputOutputPair;
import gov.sandia.cognition.learning.function.categorization.DefaultKernelBinaryCategorizer;
import gov.sandia.cognition.learning.function.kernel.Kernel;
import gov.sandia.cognition.math.matrix.VectorFactory;

/**
 * An abstract implementation of the {@code KernelizableBinaryCategorizerOnlineLearner}
 * interface. It handles a lot of the convenience methods to string them
 * together, making it necessary for sub-classes to only implement one
 * update method.
 * 
 * @author  Justin Basilico
 * @since   3.3.0
 */
public abstract class AbstractKernelizableBinaryCategorizerOnlineLearner
    extends AbstractOnlineLinearBinaryCategorizerLearner
    implements KernelizableBinaryCategorizerOnlineLearner
{

    /**
     * Creates a new {@code AbstractKernelizableBinaryCategorizerOnlineLearner}.
     */
    public AbstractKernelizableBinaryCategorizerOnlineLearner()
    {
        super();
    }

    /**
     * Creates a new {@code AbstractKernelizableBinaryCategorizerOnlineLearner}
     * with the given vector factory.
     *
     * @param   vectorFactory
     *      The vector factory to use.
     */
    public AbstractKernelizableBinaryCategorizerOnlineLearner(
        final VectorFactory vectorFactory)
    {
        super(vectorFactory);
    }

    @Override
    public  DefaultKernelBinaryCategorizer createInitialLearnedObject(
        final Kernel kernel)
    {
        return new DefaultKernelBinaryCategorizer(
            kernel);
    }

    @Override
    public  void update(
        final DefaultKernelBinaryCategorizer target,
        final Iterable> data)
    {
        for (InputOutputPair example : data)
        {
            this.update(target, example);
        }
    }

    @Override
    public  void update(
        final DefaultKernelBinaryCategorizer target,
        final InputOutputPair data)
    {
        this.update(target, data.getInput(), data.getOutput());
    }

    @Override
    public  void update(
        final DefaultKernelBinaryCategorizer target,
        final InputType input,
        final Boolean output)
    {
        this.update(target, input, (boolean) output);
    }

    @Override
    public  DefaultKernelBinaryCategorizer learn(
        final Kernel kernel,
        final Iterable> data)
    {
        // Create the object.
        final DefaultKernelBinaryCategorizer
            result = this.createInitialLearnedObject(kernel);

        // Update it.
        this.update(result, data);

        // Return the result.
        return result;
    }

    @Override
    public  SupervisedBatchAndIncrementalLearner> createKernelLearner(
        final Kernel kernel)
    {
        // Create the kernel wrapper for the learner.
        return new KernelBinaryCategorizerOnlineLearnerAdapter(
            kernel, this);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy