in samoa-api/src/main/java/org/apache/samoa/learners/classifiers/rules/centralized/AMRulesRegressorProcessor.java [196:262]
public void trainOnInstanceImpl(Instance instance) {
/*
AMRules Algorithm
For each rule in the rule set
If rule covers the instance
if the instance is not an anomaly
Update Change Detection Tests
Compute prediction error
Call PHTest
If change is detected then
Remove rule
Else
Update sufficient statistics of rule
If number of examples in rule > Nmin
Expand rule
If ordered set then
break
If none of the rule covers the instance
Update sufficient statistics of default rule
If number of examples in default rule is multiple of Nmin
Expand default rule and add it to the set of rules
Reset the default rule
*/
boolean rulesCoveringInstance = false;
Iterator<ActiveRule> ruleIterator = this.ruleSet.iterator();
while (ruleIterator.hasNext()) {
ActiveRule rule = ruleIterator.next();
if (rule.isCovering(instance)) {
rulesCoveringInstance = true;
if (!isAnomaly(instance, rule)) {
// Update Change Detection Tests
double error = rule.computeError(instance); // Use adaptive mode error
boolean changeDetected = ((RuleActiveRegressionNode) rule.getLearningNode()).updateChangeDetection(error);
if (changeDetected) {
ruleIterator.remove();
} else {
rule.updateStatistics(instance);
if (rule.getInstancesSeen() % this.gracePeriod == 0.0) {
if (rule.tryToExpand(this.splitConfidence, this.tieThreshold)) {
rule.split();
}
}
}
if (!this.unorderedRules)
break;
}
}
}
if (!rulesCoveringInstance) {
defaultRule.updateStatistics(instance);
if (defaultRule.getInstancesSeen() % this.gracePeriod == 0.0) {
if (defaultRule.tryToExpand(this.splitConfidence, this.tieThreshold)) {
ActiveRule newDefaultRule = newRule(defaultRule.getRuleNumberID(),
(RuleActiveRegressionNode) defaultRule.getLearningNode(),
((RuleActiveRegressionNode) defaultRule.getLearningNode()).getStatisticsOtherBranchSplit()); // other branch
defaultRule.split();
defaultRule.setRuleNumberID(++ruleNumberID);
this.ruleSet.add(this.defaultRule);
defaultRule = newDefaultRule;
}
}
}
}