gov.sandia.cognition.learning.algorithm.perceptron.AbstractKernelizableBinaryCategorizerOnlineLearner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cognitive-foundry Show documentation
Show all versions of cognitive-foundry Show documentation
A single jar with all the Cognitive Foundry components.
/*
* 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 super InputType> kernel)
{
return new DefaultKernelBinaryCategorizer(
kernel);
}
@Override
public void update(
final DefaultKernelBinaryCategorizer target,
final Iterable extends InputOutputPair extends InputType, Boolean>> data)
{
for (InputOutputPair extends InputType, Boolean> example : data)
{
this.update(target, example);
}
}
@Override
public void update(
final DefaultKernelBinaryCategorizer target,
final InputOutputPair extends InputType, Boolean> 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 super InputType> kernel,
final Iterable extends InputOutputPair extends InputType, Boolean>> 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 super InputType> kernel)
{
// Create the kernel wrapper for the learner.
return new KernelBinaryCategorizerOnlineLearnerAdapter(
kernel, this);
}
}