Package moa.classifiers.rules
Class RuleClassifier
- java.lang.Object
-
- moa.AbstractMOAObject
-
- moa.options.AbstractOptionHandler
-
- moa.classifiers.AbstractClassifier
-
- moa.classifiers.rules.RuleClassifier
-
- All Implemented Interfaces:
Configurable
,Serializable
,CapabilitiesHandler
,Classifier
,MultiClassClassifier
,AWTRenderable
,Learner<Example<Instance>>
,MOAObject
,OptionHandler
- Direct Known Subclasses:
RuleClassifierNBayes
public class RuleClassifier extends AbstractClassifier implements MultiClassClassifier
This classifier learn ordered and unordered rule set from data stream. This algorithm also does the detection of anomalies.Learning Decision RuleClassifications from Data Streams, IJCAI 2011, J. Gama, P. Kosina
Parameters:
- -p: Minimum value of p
- -t: Tie Threshold
- -c: Split Confidence
- -g: GracePeriod, the number of instances a leaf should observe between split attempts
- -o: Prediction function to use. Ex:FirstHit
- -r: Learn ordered or unordered rule
- Version:
- $Revision: 2 $
- Author:
- P. Kosina, E. Almeida, J. Gama
- See Also:
- Serialized Form
-
-
Field Summary
-
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 RuleClassifier()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
checkBestAttrib(double n, AutoExpandVector<AttributeClassObserver> observerss, DoubleVector observedClassDistribution)
double
computeAnomalySupervised(RuleClassification rl, int ruleIndex, Instance inst)
double
computeAnomalyUnsupervised(RuleClassification rl, int ruleIndex, Instance inst)
double
ComputeHoeffdingBound(double range, double confidence, double n)
double
computeMean(double sum, int size)
double
computeProbability(double mean, double sd, double value)
double
computeSD(double squaredVal, double val, int size)
void
createRule(Instance inst)
double
entropy(DoubleVector ValorDistClassE)
void
expandeRule(RuleClassification rl, Instance inst, int ruleIndex)
void
findBestValEntropy(BinaryTreeNumericAttributeClassObserver.Node node, DoubleVector classCountL, DoubleVector classCountR, boolean status, double minEntropy, DoubleVector parentCCLeft)
void
findBestValEntropyNominalAtt(AutoExpandVector<DoubleVector> attrib, int attNumValues)
protected double[]
firstHit(Instance inst)
protected double[]
getBestSecondBestEntropy(DoubleVector entropy)
int
getCountNominalAttrib(ArrayList<Predicates> predicateSet)
void
getModelDescription(StringBuilder out, int indent)
Returns a string representation of the model.void
getModelDescriptionNoAnomalyDetection(StringBuilder out, int indent)
protected Measurement[]
getModelMeasurementsImpl()
Gets the current measurements of this classifier.
The reason for ...Impl methods: ease programmer burden by not requiring them to remember calls to super in overridden methods.String
getPurposeString()
Dictionary with option texts and objectsprotected double
getRuleMajorityClassIndex(RuleClassification r)
double[]
getVotesForInstance(Instance inst)
Predicts the class memberships for a given instance.double
getWeightSeen()
void
initializeRuleStatistics(RuleClassification rl, Predicates pred, Instance inst)
boolean
isRandomizable()
Gets whether this learner needs a random seed.void
mainFindBestValEntropy(BinaryTreeNumericAttributeClassObserver.Node root)
void
manageMemory(int currentByteSize, int maxByteSize)
protected AttributeClassObserver
newNominalClassObserver()
protected AttributeClassObserver
newNumericClassObserver()
protected AttributeClassObserver
newNumericClassObserver2()
protected double[]
oberversDistribProb(Instance inst, DoubleVector classDistrib)
void
printAnomaliesSupervised(StringBuilder out, int indent)
void
printAnomaliesUnsupervised(StringBuilder out, int indent)
void
resetLearningImpl()
Resets this classifier.protected BigDecimal
round(double val)
void
theBestAttributes(Instance instance, AutoExpandVector<AttributeClassObserver> observersParameter)
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.void
updateRuleAttribStatistics(Instance inst, RuleClassification rl, int ruleIndex)
protected double[]
weightedMax(Instance inst)
protected double[]
weightedSum(Instance inst)
-
Methods inherited from class moa.classifiers.AbstractClassifier
contextIsCompatible, copy, correctlyClassifies, defineImmutableCapabilities, getAttributeNameString, getAWTRenderer, getClassLabelString, getClassNameString, getDescription, getModel, getModelContext, getModelMeasurements, getNominalValueString, getPredictionForInstance, getPredictionForInstance, getSubClassifiers, getSublearners, getVotesForInstance, modelAttIndexToInstanceAttIndex, modelAttIndexToInstanceAttIndex, prepareForUseImpl, 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
-
instance
protected Instance instance
-
attributeObservers
protected AutoExpandVector<AttributeClassObserver> attributeObservers
-
attributeObserversGauss
protected AutoExpandVector<AttributeClassObserver> attributeObserversGauss
-
observedClassDistribution
protected DoubleVector observedClassDistribution
-
saveBestEntropy
protected DoubleVector saveBestEntropy
-
saveBestEntropyNominalAttrib
protected DoubleVector saveBestEntropyNominalAttrib
-
ruleClassIndex
protected DoubleVector ruleClassIndex
-
saveBestGlobalEntropy
protected DoubleVector saveBestGlobalEntropy
-
ruleSet
protected ArrayList<RuleClassification> ruleSet
-
ruleSetAnomalies
protected ArrayList<RuleClassification> ruleSetAnomalies
-
ruleAttribAnomalyStatistics
protected ArrayList<ArrayList<ArrayList<Double>>> ruleAttribAnomalyStatistics
-
ruleSetAnomaliesSupervised
protected ArrayList<RuleClassification> ruleSetAnomaliesSupervised
-
ruleAttribAnomalyStatisticsSupervised
protected ArrayList<ArrayList<ArrayList<Double>>> ruleAttribAnomalyStatisticsSupervised
-
PminOption
public FloatOption PminOption
-
splitConfidenceOption
public FloatOption splitConfidenceOption
-
tieThresholdOption
public FloatOption tieThresholdOption
-
anomalyProbabilityThresholdOption
public FloatOption anomalyProbabilityThresholdOption
-
probabilityThresholdOption
public FloatOption probabilityThresholdOption
-
anomalyNumInstThresholdOption
public IntOption anomalyNumInstThresholdOption
-
gracePeriodOption
public IntOption gracePeriodOption
-
predictionFunctionOption
public MultiChoiceOption predictionFunctionOption
-
orderedRulesOption
public FlagOption orderedRulesOption
-
anomalyDetectionOption
public FlagOption anomalyDetectionOption
-
Supervised
public FlagOption Supervised
-
Unsupervised
public FlagOption Unsupervised
-
-
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
-
getVotesForInstance
public double[] getVotesForInstance(Instance inst)
Description copied from interface:Classifier
Predicts the class memberships for a given instance. If an instance is unclassified, the returned array elements must be all zero.- 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
-
getModelMeasurementsImpl
protected Measurement[] getModelMeasurementsImpl()
Description copied from class:AbstractClassifier
Gets the current measurements of this classifier.
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:
getModelMeasurementsImpl
in classAbstractClassifier
- Returns:
- an array of measurements to be used in evaluation tasks
-
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
-
getWeightSeen
public double getWeightSeen()
-
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
-
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
-
printAnomaliesUnsupervised
public void printAnomaliesUnsupervised(StringBuilder out, int indent)
-
printAnomaliesSupervised
public void printAnomaliesSupervised(StringBuilder out, int indent)
-
getModelDescriptionNoAnomalyDetection
public void getModelDescriptionNoAnomalyDetection(StringBuilder out, int indent)
-
isRandomizable
public boolean isRandomizable()
Description copied from interface:Learner
Gets whether this learner needs a random seed. Examples of methods that needs a random seed are bagging and boosting.- Specified by:
isRandomizable
in interfaceLearner<Example<Instance>>
- Returns:
- true if the learner needs a random seed.
-
getCountNominalAttrib
public int getCountNominalAttrib(ArrayList<Predicates> predicateSet)
-
round
protected BigDecimal round(double val)
-
initializeRuleStatistics
public void initializeRuleStatistics(RuleClassification rl, Predicates pred, Instance inst)
-
updateRuleAttribStatistics
public void updateRuleAttribStatistics(Instance inst, RuleClassification rl, int ruleIndex)
-
computeAnomalyUnsupervised
public double computeAnomalyUnsupervised(RuleClassification rl, int ruleIndex, Instance inst)
-
computeAnomalySupervised
public double computeAnomalySupervised(RuleClassification rl, int ruleIndex, Instance inst)
-
computeMean
public double computeMean(double sum, int size)
-
computeSD
public double computeSD(double squaredVal, double val, int size)
-
computeProbability
public double computeProbability(double mean, double sd, double value)
-
createRule
public void createRule(Instance inst)
-
expandeRule
public void expandeRule(RuleClassification rl, Instance inst, int ruleIndex)
-
theBestAttributes
public void theBestAttributes(Instance instance, AutoExpandVector<AttributeClassObserver> observersParameter)
-
entropy
public double entropy(DoubleVector ValorDistClassE)
-
findBestValEntropy
public void findBestValEntropy(BinaryTreeNumericAttributeClassObserver.Node node, DoubleVector classCountL, DoubleVector classCountR, boolean status, double minEntropy, DoubleVector parentCCLeft)
-
mainFindBestValEntropy
public void mainFindBestValEntropy(BinaryTreeNumericAttributeClassObserver.Node root)
-
findBestValEntropyNominalAtt
public void findBestValEntropyNominalAtt(AutoExpandVector<DoubleVector> attrib, int attNumValues)
-
ComputeHoeffdingBound
public double ComputeHoeffdingBound(double range, double confidence, double n)
-
checkBestAttrib
public boolean checkBestAttrib(double n, AutoExpandVector<AttributeClassObserver> observerss, DoubleVector observedClassDistribution)
-
getBestSecondBestEntropy
protected double[] getBestSecondBestEntropy(DoubleVector entropy)
-
getRuleMajorityClassIndex
protected double getRuleMajorityClassIndex(RuleClassification r)
-
oberversDistribProb
protected double[] oberversDistribProb(Instance inst, DoubleVector classDistrib)
-
firstHit
protected double[] firstHit(Instance inst)
-
weightedMax
protected double[] weightedMax(Instance inst)
-
weightedSum
protected double[] weightedSum(Instance inst)
-
newNominalClassObserver
protected AttributeClassObserver newNominalClassObserver()
-
newNumericClassObserver
protected AttributeClassObserver newNumericClassObserver()
-
newNumericClassObserver2
protected AttributeClassObserver newNumericClassObserver2()
-
manageMemory
public void manageMemory(int currentByteSize, int maxByteSize)
-
-