gov.sandia.cognition.learning.algorithm
Class CompositeBatchLearnerPair<InputType,IntermediateType,OutputType>

java.lang.Object
  extended by gov.sandia.cognition.util.AbstractCloneableSerializable
      extended by gov.sandia.cognition.learning.algorithm.CompositeBatchLearnerPair<InputType,IntermediateType,OutputType>
Type Parameters:
InputType - The type of the input data. It is passed to the first learning algorithm to learn the evaluator that takes this type and returns the intermediate type.
IntermediateType - The type of the output of the first learned function that is used as input to the second learner. It is also the input type for the second learned evaluator that returns the output type.
OutputType - The type of output of the evaluator learned by the second learner. It is also the output type of the composite evaluator pair.
All Implemented Interfaces:
BatchLearner<Collection<? extends InputType>,CompositeEvaluatorPair<InputType,IntermediateType,OutputType>>, CloneableSerializable, Pair<BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>>,BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>>>, Serializable, Cloneable

public class CompositeBatchLearnerPair<InputType,IntermediateType,OutputType>
extends AbstractCloneableSerializable
implements BatchLearner<Collection<? extends InputType>,CompositeEvaluatorPair<InputType,IntermediateType,OutputType>>, Pair<BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>>,BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>>>

Composes together a pair of batch (typically unsupervised) learners. It takes the input data and passes it to the first learner to learn an evaluator. It then takes that first evaluator, evaluates it on it to all of the input data, and passes the resulting values as input to the second learner. It takes the evaluator learned from the second learner and then composes the two evaluators together to create a composite evaluator. Thus, this class can be used to layer learning algorithms.

Since:
3.3.3
Author:
Justin Basilico
See Also:
InputOutputTransformedBatchLearner, Serialized Form

Field Summary
protected  BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> firstLearner
          The first learner that is trained on the input data.
protected  BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> secondLearner
          The second learner that is trained on the output of the evaluator created by the first learner.
 
Constructor Summary
CompositeBatchLearnerPair()
          Creates a new, empty CompositeBatchLearnerPair.
CompositeBatchLearnerPair(BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> firstLearner, BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> secondLearner)
          Creates a new CompositeBatchLearnerPair with the given two learner.
 
Method Summary
static
<InputType,IntermediateType,OutputType>
CompositeBatchLearnerPair<InputType,IntermediateType,OutputType>
create(BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> firstLearner, BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> secondLearner)
          Creates a new CompositeBatchLearnerPair from the given learners.
static
<InputType,IntermediateType,OutputType>
CompositeBatchLearnerPair<InputType,IntermediateType,OutputType>
createInputTransformed(Evaluator<? super InputType,? extends IntermediateType> inputTransform, BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> learner)
          Creates a new CompositeBatchLearnerPair from the given input transform and learner.
static
<InputType,IntermediateType,OutputType>
CompositeBatchLearnerPair<InputType,IntermediateType,OutputType>
createOutputTransformed(BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> learner, Evaluator<? super IntermediateType,? extends OutputType> outputTransform)
          Creates a new CompositeBatchLearnerPair from the given learner and output transform..
 BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> getFirst()
          Gets the first object.
 BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> getFirstLearner()
          Gets the first learner that is applied to the input data.
 BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> getSecond()
          Gets the second object.
 BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> getSecondLearner()
          Gets the second learner that is applied to the output of the first learner.
 CompositeEvaluatorPair<InputType,IntermediateType,OutputType> learn(Collection<? extends InputType> data)
          Learn by calling the first learner on all the input values.
 void setFirstLearner(BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> firstLearner)
          Sets the first learner that is applied to the input data.
 void setSecondLearner(BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> secondLearner)
          Sets the second learner that is applied to the output of the first learner.
 
Methods inherited from class gov.sandia.cognition.util.AbstractCloneableSerializable
clone
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface gov.sandia.cognition.util.CloneableSerializable
clone
 

Field Detail

firstLearner

protected BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> firstLearner
The first learner that is trained on the input data.


secondLearner

protected BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> secondLearner
The second learner that is trained on the output of the evaluator created by the first learner.

Constructor Detail

CompositeBatchLearnerPair

public CompositeBatchLearnerPair()
Creates a new, empty CompositeBatchLearnerPair.


CompositeBatchLearnerPair

public CompositeBatchLearnerPair(BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> firstLearner,
                                 BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> secondLearner)
Creates a new CompositeBatchLearnerPair with the given two learner.

Parameters:
firstLearner - The first learner that is trained on the input data.
secondLearner - The second learner that is trained based on the output of the first learner.
Method Detail

learn

public CompositeEvaluatorPair<InputType,IntermediateType,OutputType> learn(Collection<? extends InputType> data)
Learn by calling the first learner on all the input values. Then the resulting evaluator is applied to all of the input data to create a set of intermediate data. The second learner is then called on all the intermediate data to create the second evaluator that maps to the output type.

Specified by:
learn in interface BatchLearner<Collection<? extends InputType>,CompositeEvaluatorPair<InputType,IntermediateType,OutputType>>
Parameters:
data - The training data.
Returns:
The composite evaluator pair that applies the two learned evaluators in sequence.

getFirst

public BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> getFirst()
Description copied from interface: Pair
Gets the first object.

Specified by:
getFirst in interface Pair<BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>>,BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>>>
Returns:
The first object.

getSecond

public BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> getSecond()
Description copied from interface: Pair
Gets the second object.

Specified by:
getSecond in interface Pair<BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>>,BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>>>
Returns:
The second object.

getFirstLearner

public BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> getFirstLearner()
Gets the first learner that is applied to the input data.

Returns:
The first learner.

setFirstLearner

public void setFirstLearner(BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> firstLearner)
Sets the first learner that is applied to the input data.

Parameters:
firstLearner - The first learner.

getSecondLearner

public BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> getSecondLearner()
Gets the second learner that is applied to the output of the first learner.

Returns:
The second learner.

setSecondLearner

public void setSecondLearner(BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> secondLearner)
Sets the second learner that is applied to the output of the first learner.

Parameters:
secondLearner - The second learner.

create

public static <InputType,IntermediateType,OutputType> CompositeBatchLearnerPair<InputType,IntermediateType,OutputType> create(BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> firstLearner,
                                                                                                                              BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> secondLearner)
Creates a new CompositeBatchLearnerPair from the given learners.

Type Parameters:
InputType - The type of the input data. It is passed to the first learning algorithm to learn the evaluator that takes this type and returns the intermediate type.
IntermediateType - The type of the output of the first learned function that is used as input to the second learner. It is also the input type for the second learned evaluator that returns the output type.
OutputType - The type of output of the evaluator learned by the second learner. It is also the output type of the composite evaluator pair.
Parameters:
firstLearner - The first learner that is trained on the input data.
secondLearner - The second learner that is trained based on the output of the first learner.
Returns:
A new composite evaluator pair of the given learners.

createInputTransformed

public static <InputType,IntermediateType,OutputType> CompositeBatchLearnerPair<InputType,IntermediateType,OutputType> createInputTransformed(Evaluator<? super InputType,? extends IntermediateType> inputTransform,
                                                                                                                                              BatchLearner<? super Collection<? extends IntermediateType>,? extends Evaluator<? super IntermediateType,? extends OutputType>> learner)
Creates a new CompositeBatchLearnerPair from the given input transform and learner.

Type Parameters:
InputType - The type of the input data. It is passed to the input transform takes this type and returns the intermediate type.
IntermediateType - The type of the output of the input transform is used as input to the learner. It is also the input type for the learned evaluator that returns the output type.
OutputType - The type of output of the learned evaluator. It is also the output type of the composite evaluator pair.
Parameters:
inputTransform - The input transform to apply to the input data.
learner - The learner that is trained based on the output of the transform.
Returns:
A new composite evaluator pair of the given transform and learner.

createOutputTransformed

public static <InputType,IntermediateType,OutputType> CompositeBatchLearnerPair<InputType,IntermediateType,OutputType> createOutputTransformed(BatchLearner<? super Collection<? extends InputType>,? extends Evaluator<? super InputType,? extends IntermediateType>> learner,
                                                                                                                                               Evaluator<? super IntermediateType,? extends OutputType> outputTransform)
Creates a new CompositeBatchLearnerPair from the given learner and output transform..

Type Parameters:
InputType - The type of the input data. It is passed to the learning algorithm to learn the evaluator that takes this type and returns the intermediate type.
IntermediateType - The type of the output of the first learned function that is used as input to the output transform.
OutputType - The type of output of the output transform. It is also the output type of the composite evaluator pair.
Parameters:
learner - The learner that is trained on the input data.
outputTransform - The output transform that is composed with the learned function.
Returns:
A new composite evaluator pair of the given learner and transform.