diff --git a/adaa.analytics.rules/build.gradle b/adaa.analytics.rules/build.gradle index ec6be1d..047077f 100644 --- a/adaa.analytics.rules/build.gradle +++ b/adaa.analytics.rules/build.gradle @@ -27,7 +27,7 @@ codeQuality { } sourceCompatibility = 1.8 -version = '1.7.7' +version = '1.7.8' jar { diff --git a/adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationExpertSnC.java b/adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationExpertSnC.java index 5826a1c..0538db7 100644 --- a/adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationExpertSnC.java +++ b/adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationExpertSnC.java @@ -14,8 +14,7 @@ ******************************************************************************/ package adaa.analytics.rules.logic.induction; -import java.util.HashSet; -import java.util.Set; +import java.util.*; import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicInteger; import java.util.logging.Level; @@ -64,8 +63,12 @@ public ClassificationRuleSet run(ExampleSet dataset) beginTime = System.nanoTime(); ClassificationRuleSet ruleset = (ClassificationRuleSet)factory.create(dataset); - Attribute label = dataset.getAttributes().getLabel(); - NominalMapping mapping = label.getMapping(); + Attribute outputAttr = dataset.getAttributes().getLabel(); + NominalMapping mapping = outputAttr.getMapping(); + List labels = new ArrayList<>(); + labels.addAll(mapping.getValues()); + Collections.sort(labels); + int totalExpertRules = 0; int totalAutoRules = 0; @@ -76,7 +79,9 @@ public ClassificationRuleSet run(ExampleSet dataset) finder.preprocess(dataset); // iterate over all classes - for (int classId = 0; classId < mapping.size(); ++classId) { + for (String label : labels) { + int classId = mapping.getIndex(label); + Logger.log("Class " + label + " (" +classId + ") started\n" , Level.FINE); IntegerBitSet positives = new IntegerBitSet(dataset.size()); IntegerBitSet negatives = new IntegerBitSet(dataset.size()); @@ -185,7 +190,7 @@ public ClassificationRuleSet run(ExampleSet dataset) while (carryOn) { Rule rule = new ClassificationRule( new CompoundCondition(), - new ElementaryCondition(label.getName(), new SingletonSet((double)classId, mapping.getValues()))); + new ElementaryCondition(outputAttr.getName(), new SingletonSet((double)classId, mapping.getValues()))); rule.setWeighted_P(weighted_P); rule.setWeighted_N(weighted_N); diff --git a/adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationSnC.java b/adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationSnC.java index e9d3f28..481552c 100644 --- a/adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationSnC.java +++ b/adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationSnC.java @@ -67,6 +67,9 @@ public RuleSetBase run(ExampleSet dataset) { : dataset.getAttributes().getSpecial(ContrastRule.CONTRAST_ATTRIBUTE_ROLE); NominalMapping mapping = outputAttr.getMapping(); + List labels = new ArrayList<>(); + labels.addAll(mapping.getValues()); + Collections.sort(labels); boolean weighted = (dataset.getAttributes().getWeight() != null); @@ -78,9 +81,9 @@ public RuleSetBase run(ExampleSet dataset) { double defaultClassP = 0; // iterate over all classes - for (int cid = 0; cid < mapping.size(); ++cid) { - final int classId = cid; - Logger.log("Class " + classId + " started\n" , Level.FINE); + for (String label : labels) { + int classId = mapping.getIndex(label); + Logger.log("Class " + label + " (" +classId + ") started\n" , Level.FINE); preprocessClass(dataset, classId);