Skip to content

Commit 3e9ded6

Browse files
committed
Nominal attribute values investigated in the alphabetical order.
1 parent a7cd5e2 commit 3e9ded6

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

adaa.analytics.rules/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ codeQuality {
2727
}
2828

2929
sourceCompatibility = 1.8
30-
version = '1.7.8'
30+
version = '1.7.9'
3131

3232

3333
jar {

adaa.analytics.rules/src/main/java/adaa/analytics/rules/logic/induction/ClassificationFinder.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class ClassificationFinder extends AbstractFinder {
4444

4545
protected Map<Attribute, Map<Double, IntegerBitSet>> precalculatedCoveringsComplement;
4646

47+
protected Map<Attribute, Integer[]> attributeValuesOrder;
48+
4749
/**
4850
* Initializes induction parameters.
4951
* @param params Induction parameters.
@@ -66,6 +68,7 @@ public ExampleSet preprocess(ExampleSet trainSet) {
6668
return trainSet;
6769
}
6870

71+
attributeValuesOrder = new HashMap<Attribute, Integer[]>();
6972
precalculatedCoverings = new HashMap<Attribute, Map<Double, IntegerBitSet>>();
7073
precalculatedCoveringsComplement = new HashMap<Attribute, Map<Double, IntegerBitSet>>();
7174
Attributes attributes = trainSet.getAttributes();
@@ -78,9 +81,19 @@ public ExampleSet preprocess(ExampleSet trainSet) {
7881
Future f = pool.submit( () -> {
7982
Map<Double, IntegerBitSet> attributeCovering = new TreeMap<Double, IntegerBitSet>();
8083
Map<Double, IntegerBitSet> attributeCoveringComplement = new TreeMap<Double, IntegerBitSet>();
84+
Integer[] valuesOrder = null;
8185

8286
// check if attribute is nominal
8387
if (attr.isNominal()) {
88+
// get orders
89+
valuesOrder = new Integer[attr.getMapping().size()];
90+
List<String> labels = new ArrayList<>();
91+
labels.addAll(attr.getMapping().getValues());
92+
Collections.sort(labels);
93+
for (int j = 0; j < labels.size(); ++j) {
94+
valuesOrder[j] = attr.getMapping().getIndex(labels.get(j));
95+
}
96+
8497
// prepare bit vectors
8598
for (int val = 0; val != attr.getMapping().size(); ++val) {
8699
attributeCovering.put((double) val, new IntegerBitSet(trainSet.size()));
@@ -108,6 +121,7 @@ public ExampleSet preprocess(ExampleSet trainSet) {
108121
synchronized (this) {
109122
precalculatedCoverings.put(attr, attributeCovering);
110123
precalculatedCoveringsComplement.put(attr, attributeCoveringComplement);
124+
attributeValuesOrder.put(attr, valuesOrder);
111125
}
112126
});
113127

@@ -664,9 +678,10 @@ class TotalPosNeg {
664678
} else {
665679
// unweighted case
666680
// try all possible conditions
667-
for (int i = 0; i < attr.getMapping().size(); ++i) {
681+
for (int j = 0; j < attr.getMapping().size(); ++j) {
668682

669683
// evaluate straight condition
684+
int i = attributeValuesOrder.get(attr)[j];
670685
IntegerBitSet conditionCovered = precalculatedCoverings.get(attr).get((double) i);
671686
double p = conditionCovered.calculateIntersectionSize(rule.getCoveredPositives());
672687
int toCover_p = conditionCovered.calculateIntersectionSize((IntegerBitSet) coveredByRule, (IntegerBitSet) uncoveredPositives);

0 commit comments

Comments
 (0)