Package moa.classifiers.meta
Class AccuracyWeightedEnsemble
- java.lang.Object
-
- moa.AbstractMOAObject
-
- moa.options.AbstractOptionHandler
-
- moa.classifiers.AbstractClassifier
-
- moa.classifiers.meta.AccuracyWeightedEnsemble
-
- All Implemented Interfaces:
Configurable
,Serializable
,CapabilitiesHandler
,Classifier
,MultiClassClassifier
,AWTRenderable
,Learner<Example<Instance>>
,MOAObject
,OptionHandler
public class AccuracyWeightedEnsemble extends AbstractClassifier implements MultiClassClassifier
The Accuracy Weighted Ensemble classifier as proposed by Wang et al. in "Mining concept-drifting data streams using ensemble classifiers", KDD 2003.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected Classifier
candidateClassifier
protected int
chunkSize
IntOption
chunkSizeOption
Chunk size.protected long[]
classDistributions
protected Instances
currentChunk
protected Classifier[]
ensemble
protected double[]
ensembleWeights
ClassOption
learnerOption
Type of classifier to use as a component classifier.protected int
maxMemberCount
protected int
maxStoredCount
FloatOption
memberCountOption
Number of component classifiers.protected int
numFolds
IntOption
numFoldsOption
Number of folds in candidate classifier cross-validation.protected int
processedInstances
FloatOption
storedCountOption
Number of classifiers remembered and available for ensemble construction.protected Classifier[]
storedLearners
protected double[][]
storedWeights
The weights of stored classifiers.protected static Comparator<double[]>
weightComparator
Simple weight comparator.-
Fields inherited from class moa.classifiers.AbstractClassifier
classifierRandom, modelContext, randomSeed, randomSeedOption, trainingWeightSeenByModel
-
Fields inherited from class moa.options.AbstractOptionHandler
config
-
-
Constructor Summary
Constructors Constructor Description AccuracyWeightedEnsemble()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Classifier
addToStored(Classifier newClassifier, double newClassifiersWeight)
Adds a classifier to the storage.protected double
computeCandidateWeight(Classifier candidate, Instances chunk, int numFolds)
Computes the weight of a candidate classifier.protected double
computeMseR()
Computes the MSEr threshold.protected double
computeWeight(Classifier learner, Instances chunk)
Computes the weight of a given classifie.protected void
discardModel(int index)
Removes the classifier at a given index from the model, thus decreasing the models size.void
getModelDescription(StringBuilder out, int indent)
Returns a string representation of the model.protected Measurement[]
getModelMeasurementsImpl()
Adds ensemble weights to the measurements.String
getPurposeString()
Dictionary with option texts and objectsClassifier[]
getSubClassifiers()
Gets the classifiers of this ensemble.double[]
getVotesForInstance(Instance inst)
Predicts a class for an example.boolean
isRandomizable()
Determines whether the classifier is randomizable.void
prepareForUseImpl(TaskMonitor monitor, ObjectRepository repository)
This method describes the implementation of how to prepare this object for use.protected void
processChunk()
Processes a chunk.protected int
removePoorestModelBytes()
Removes the poorest classifier from the model, thus decreasing the models size.void
resetLearningImpl()
Resets this classifier.void
trainOnInstanceImpl(Instance inst)
Trains this classifier incrementally using the given instance.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods.-
Methods inherited from class moa.classifiers.AbstractClassifier
contextIsCompatible, copy, correctlyClassifies, defineImmutableCapabilities, getAttributeNameString, getAWTRenderer, getClassLabelString, getClassNameString, getDescription, getModel, getModelContext, getModelMeasurements, getNominalValueString, getPredictionForInstance, getPredictionForInstance, getSublearners, getVotesForInstance, modelAttIndexToInstanceAttIndex, modelAttIndexToInstanceAttIndex, resetLearning, setModelContext, setRandomSeed, trainingHasStarted, trainingWeightSeenByModel, trainOnInstance, trainOnInstance
-
Methods inherited from class moa.options.AbstractOptionHandler
getCLICreationString, getOptions, getPreparedClassOption, prepareClassOptions, prepareForUse, prepareForUse
-
Methods inherited from class moa.AbstractMOAObject
copy, measureByteSize, measureByteSize, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface moa.capabilities.CapabilitiesHandler
getCapabilities
-
Methods inherited from interface moa.MOAObject
measureByteSize
-
Methods inherited from interface moa.options.OptionHandler
getCLICreationString, getOptions, prepareForUse, prepareForUse
-
-
-
-
Field Detail
-
weightComparator
protected static Comparator<double[]> weightComparator
Simple weight comparator.
-
learnerOption
public ClassOption learnerOption
Type of classifier to use as a component classifier.
-
memberCountOption
public FloatOption memberCountOption
Number of component classifiers.
-
storedCountOption
public FloatOption storedCountOption
Number of classifiers remembered and available for ensemble construction.
-
chunkSizeOption
public IntOption chunkSizeOption
Chunk size.
-
numFoldsOption
public IntOption numFoldsOption
Number of folds in candidate classifier cross-validation.
-
classDistributions
protected long[] classDistributions
-
ensemble
protected Classifier[] ensemble
-
storedLearners
protected Classifier[] storedLearners
-
ensembleWeights
protected double[] ensembleWeights
-
storedWeights
protected double[][] storedWeights
The weights of stored classifiers. storedWeights[x][0] = weight storedWeights[x][1] = classifier
-
processedInstances
protected int processedInstances
-
chunkSize
protected int chunkSize
-
numFolds
protected int numFolds
-
maxMemberCount
protected int maxMemberCount
-
maxStoredCount
protected int maxStoredCount
-
candidateClassifier
protected Classifier candidateClassifier
-
currentChunk
protected Instances currentChunk
-
-
Method Detail
-
getPurposeString
public String getPurposeString()
Description copied from class:AbstractOptionHandler
Dictionary with option texts and objects- Specified by:
getPurposeString
in interfaceOptionHandler
- Overrides:
getPurposeString
in classAbstractClassifier
- Returns:
- the string with the purpose of this object
-
prepareForUseImpl
public void prepareForUseImpl(TaskMonitor monitor, ObjectRepository repository)
Description copied from class:AbstractOptionHandler
This method describes the implementation of how to prepare this object for use. All classes that extends this class have to implementprepareForUseImpl
and notprepareForUse
sinceprepareForUse
callsprepareForUseImpl
.- Overrides:
prepareForUseImpl
in classAbstractClassifier
- Parameters:
monitor
- the TaskMonitor to userepository
- the ObjectRepository to use
-
resetLearningImpl
public void resetLearningImpl()
Description copied from class:AbstractClassifier
Resets this classifier. It must be similar to starting a new classifier from scratch.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Specified by:
resetLearningImpl
in classAbstractClassifier
-
trainOnInstanceImpl
public void trainOnInstanceImpl(Instance inst)
Description copied from class:AbstractClassifier
Trains this classifier incrementally using the given instance.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods. Note that this will produce compiler errors if not overridden.- Specified by:
trainOnInstanceImpl
in classAbstractClassifier
- Parameters:
inst
- the instance to be used for training
-
processChunk
protected void processChunk()
Processes a chunk.
-
computeCandidateWeight
protected double computeCandidateWeight(Classifier candidate, Instances chunk, int numFolds)
Computes the weight of a candidate classifier.- Parameters:
candidate
- Candidate classifier.chunk
- Data chunk of examples.numFolds
- Number of folds in candidate classifier cross-validation.- Returns:
- Candidate classifier weight.
-
computeWeight
protected double computeWeight(Classifier learner, Instances chunk)
Computes the weight of a given classifie.- Parameters:
learner
- Classifier to calculate weight for.chunk
- Data chunk of examples.- Returns:
- The given classifier's weight.
-
computeMseR
protected double computeMseR()
Computes the MSEr threshold.- Returns:
- The MSEr threshold.
-
getVotesForInstance
public double[] getVotesForInstance(Instance inst)
Predicts a class for an example.- Specified by:
getVotesForInstance
in interfaceClassifier
- Specified by:
getVotesForInstance
in classAbstractClassifier
- Parameters:
inst
- the instance to be classified- Returns:
- an array containing the estimated membership probabilities of the test instance in each class
-
getModelDescription
public void getModelDescription(StringBuilder out, int indent)
Description copied from class:AbstractClassifier
Returns a string representation of the model.- Specified by:
getModelDescription
in classAbstractClassifier
- Parameters:
out
- the stringbuilder to add the descriptionindent
- the number of characters to indent
-
getModelMeasurementsImpl
protected Measurement[] getModelMeasurementsImpl()
Adds ensemble weights to the measurements.- Specified by:
getModelMeasurementsImpl
in classAbstractClassifier
- Returns:
- an array of measurements to be used in evaluation tasks
-
isRandomizable
public boolean isRandomizable()
Determines whether the classifier is randomizable.- Specified by:
isRandomizable
in interfaceLearner<Example<Instance>>
- Returns:
- true if the learner needs a random seed.
-
getSubClassifiers
public Classifier[] getSubClassifiers()
Description copied from interface:Classifier
Gets the classifiers of this ensemble. Returns null if this learner is a single learner.- Specified by:
getSubClassifiers
in interfaceClassifier
- Overrides:
getSubClassifiers
in classAbstractClassifier
- Returns:
- an array of the learners of the ensemble
-
addToStored
protected Classifier addToStored(Classifier newClassifier, double newClassifiersWeight)
Adds a classifier to the storage.- Parameters:
newClassifier
- The classifier to add.newClassifiersWeight
- The new classifiers weight.
-
removePoorestModelBytes
protected int removePoorestModelBytes()
Removes the poorest classifier from the model, thus decreasing the models size.- Returns:
- the size of the removed classifier.
-
discardModel
protected void discardModel(int index)
Removes the classifier at a given index from the model, thus decreasing the models size.- Parameters:
index
-
-
-