gov.sandia.cognition.learning.algorithm.ensemble.BinaryBaggingLearner 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: BinaryBaggingLearner.java
* Authors: Justin Basilico
* Company: Sandia National Laboratories
* Project: Cognitive Foundry
*
* Copyright September 17, 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.algorithm.ensemble;
import gov.sandia.cognition.annotation.CodeReview;
import gov.sandia.cognition.evaluator.Evaluator;
import gov.sandia.cognition.learning.algorithm.BatchLearner;
import gov.sandia.cognition.learning.data.InputOutputPair;
import gov.sandia.cognition.util.WeightedValue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Random;
/**
* The {@code BinaryBaggingLearner} implements the Bagging learning algorithm.
* At each step, the algorithm creates a "bag" of data by sampling from the
* given data with replacement. It then passes the bag of data to the given
* learner to learn a new binary categorizer, which it then adds to the
* ensemble. All learners are given an equal weight of 1.0.
*
* @param Input class of the {@code Collection}
* for the dataset, for example, something like Vector or String
* @author Justin Basilico
* @since 2.0
*/
@CodeReview(
reviewer="Kevin R. Dixon",
date="2008-07-23",
changesNeeded=false,
comments={
"Cleaned up javadoc a little bit with code annotations.",
"Otherwise, looks fine."
}
)
public class BinaryBaggingLearner
extends AbstractBaggingLearner,
WeightedBinaryEnsemble>>
{
/**
* Creates a new instance of BinaryBaggingLearner.
*/
public BinaryBaggingLearner()
{
this(null);
}
/**
* Creates a new instance of BinaryBaggingLearner.
*
* @param learner
* The learner to use to create the categorizer on each iteration.
*/
public BinaryBaggingLearner(
final BatchLearner super Collection extends InputOutputPair extends InputType, Boolean>>, ? extends Evaluator super InputType, ? extends Boolean>>
learner)
{
this(learner, DEFAULT_MAX_ITERATIONS);
}
/**
* Creates a new instance of BinaryBaggingLearner.
*
* @param learner
* The learner to use to create the categorizer on each iteration.
* @param maxIterations
* The maximum number of iterations to run for, which is also the
* number of learners to create.
*/
public BinaryBaggingLearner(
final BatchLearner super Collection extends InputOutputPair extends InputType, Boolean>>, ? extends Evaluator super InputType, ? extends Boolean>>
learner,
final int maxIterations)
{
this(learner, maxIterations, new Random());
}
/**
* Creates a new instance of BinaryBaggingLearner.
*
* @param learner
* The learner to use to create the categorizer on each iteration.
* @param maxIterations
* The maximum number of iterations to run for, which is also the
* number of learners to create.
* @param random
* The random number generator to use.
*/
public BinaryBaggingLearner(
final BatchLearner super Collection extends InputOutputPair extends InputType, Boolean>>, ? extends Evaluator super InputType, ? extends Boolean>>
learner,
final int maxIterations,
final Random random)
{
this(learner, maxIterations, DEFAULT_PERCENT_TO_SAMPLE, random);
}
/**
* Creates a new instance of BinaryBaggingLearner.
*
* @param learner
* The learner to use to create the ensemble member on each iteration.
* @param maxIterations
* The maximum number of iterations to run for, which is also the
* number of learners to create.
* @param percentToSample
* The percentage of the total size of the data to sample on each
* iteration. Must be positive.
* @param random
* The random number generator to use.
*/
public BinaryBaggingLearner(
final BatchLearner super Collection extends InputOutputPair extends InputType, Boolean>>, ? extends Evaluator super InputType, ? extends Boolean>>
learner,
final int maxIterations,
final double percentToSample,
final Random random)
{
super(learner, maxIterations, percentToSample, random);
}
@Override
protected WeightedBinaryEnsemble> createInitialEnsemble()
{
return new WeightedBinaryEnsemble>(
new ArrayList>>(
this.getMaxIterations()));
}
@Override
protected void addEnsembleMember(
final Evaluator super InputType, ? extends Boolean> member)
{
this.ensemble.add(member);
}
}