Skip to content

Commit

Permalink
Nominal attribute values investigated in the alphabetical order.
Browse files Browse the repository at this point in the history
  • Loading branch information
agudys committed Apr 2, 2024
1 parent a7cd5e2 commit 3e9ded6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion adaa.analytics.rules/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ codeQuality {
}

sourceCompatibility = 1.8
version = '1.7.8'
version = '1.7.9'


jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class ClassificationFinder extends AbstractFinder {

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

protected Map<Attribute, Integer[]> attributeValuesOrder;

/**
* Initializes induction parameters.
* @param params Induction parameters.
Expand All @@ -66,6 +68,7 @@ public ExampleSet preprocess(ExampleSet trainSet) {
return trainSet;
}

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

// check if attribute is nominal
if (attr.isNominal()) {
// get orders
valuesOrder = new Integer[attr.getMapping().size()];
List<String> labels = new ArrayList<>();
labels.addAll(attr.getMapping().getValues());
Collections.sort(labels);
for (int j = 0; j < labels.size(); ++j) {
valuesOrder[j] = attr.getMapping().getIndex(labels.get(j));
}

// prepare bit vectors
for (int val = 0; val != attr.getMapping().size(); ++val) {
attributeCovering.put((double) val, new IntegerBitSet(trainSet.size()));
Expand Down Expand Up @@ -108,6 +121,7 @@ public ExampleSet preprocess(ExampleSet trainSet) {
synchronized (this) {
precalculatedCoverings.put(attr, attributeCovering);
precalculatedCoveringsComplement.put(attr, attributeCoveringComplement);
attributeValuesOrder.put(attr, valuesOrder);
}
});

Expand Down Expand Up @@ -664,9 +678,10 @@ class TotalPosNeg {
} else {
// unweighted case
// try all possible conditions
for (int i = 0; i < attr.getMapping().size(); ++i) {
for (int j = 0; j < attr.getMapping().size(); ++j) {

// evaluate straight condition
int i = attributeValuesOrder.get(attr)[j];
IntegerBitSet conditionCovered = precalculatedCoverings.get(attr).get((double) i);
double p = conditionCovered.calculateIntersectionSize(rule.getCoveredPositives());
int toCover_p = conditionCovered.calculateIntersectionSize((IntegerBitSet) coveredByRule, (IntegerBitSet) uncoveredPositives);
Expand Down

0 comments on commit 3e9ded6

Please sign in to comment.