Skip to content

Commit a5cab38

Browse files
committed
Added tests
1 parent 927eca9 commit a5cab38

File tree

109 files changed

+6737
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+6737
-131
lines changed

pom.xml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>lac</groupId>
66
<artifactId>lac</artifactId>
7-
<version>0.1.0</version>
7+
<version>0.2.0</version>
88
<packaging>jar</packaging>
99

1010
<name>lac</name>
@@ -21,6 +21,28 @@
2121
<artifactId>snakeyaml</artifactId>
2222
<version>1.24</version>
2323
</dependency>
24+
25+
<!-- https://mvnrepository.com/artifact/junit/junit -->
26+
<dependency>
27+
<groupId>junit</groupId>
28+
<artifactId>junit</artifactId>
29+
<version>4.12</version>
30+
<scope>test</scope>
31+
</dependency>
32+
33+
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
34+
<dependency>
35+
<groupId>org.mockito</groupId>
36+
<artifactId>mockito-core</artifactId>
37+
<version>3.1.0</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>com.github.stefanbirkner</groupId>
42+
<artifactId>system-rules</artifactId>
43+
<version>1.19.0</version>
44+
<scope>test</scope>
45+
</dependency>
2446
</dependencies>
2547

2648
<build>

src/main/java/lac/algorithms/Classifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class Classifier {
2828
/**
2929
* Value used when the classifier is not able to perform a prediction
3030
*/
31-
protected static short NO_PREDICTION = -1;
31+
public static short NO_PREDICTION = -1;
3232

3333
/**
3434
* Array of rules forming the classifier

src/main/java/lac/algorithms/Rule.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public long getSupportRule() {
133133
*
134134
* @return relative support for the consequent
135135
*/
136-
public long getSupportConsequent() {
136+
public long getSupportKlass() {
137137
return this.supportKlass;
138138
}
139139

@@ -153,12 +153,12 @@ public boolean matching(Short[] example) {
153153
/**
154154
* Function to check if a rule is equal to another given.
155155
*
156-
* @param rule Rule to compare with current
156+
* @param other Rule to compare with current
157157
* @return true if they are equal, false otherwise
158158
*/
159159
@Override
160-
public boolean equals(Object o) {
161-
Rule rule = (Rule) o;
160+
public boolean equals(Object other) {
161+
Rule rule = (Rule) other;
162162

163163
if (this.klass != rule.getKlass())
164164
return false;
@@ -242,7 +242,7 @@ public long getSupportAntecedent() {
242242
/**
243243
* Function which sets the rule's klass.
244244
*
245-
* @param klasss rule's klass
245+
* @param klass rule's klass
246246
*/
247247
public void setKlass(short klass) {
248248
this.klass = klass;

src/main/java/lac/algorithms/acn/Rule.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,24 +183,26 @@ public boolean matching(Short[] example) {
183183
if (antecedent.isEmpty())
184184
return true;
185185

186-
if (this.isNegative()) {
186+
if (!this.isNegative()) {
187+
return super.matching(example);
188+
} else {
187189
ArrayList<Short> positiveAntecedent = new ArrayList<Short>();
190+
List<Short> exampleA = Arrays.asList(example);
188191

189192
for (int i = 0; i < this.antecedent.size(); i++) {
190193
if (this.negatedItems.get(i)) {
191194
short negativeItem = this.antecedent.get(i);
192195

193196
// If contain negative Item, it cannot match this example
194-
if (antecedent.contains(negativeItem))
197+
if (exampleA.contains(negativeItem)) {
195198
return false;
199+
}
196200
} else {
197201
positiveAntecedent.add(this.antecedent.get(i));
198202
}
199203
}
200204

201205
return Utils.isSubset(positiveAntecedent, example);
202-
} else {
203-
return super.matching(example);
204206
}
205207
}
206208
}

src/main/java/lac/algorithms/adt/Config.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ public void setMinConf(Double confidence) {
5151
this.minConf = confidence;
5252
}
5353

54+
/**
55+
* Sets the minimum confidence
56+
*
57+
* @param confidence
58+
*/
59+
public void setMinConf(Integer confidence) {
60+
this.minConf = confidence;
61+
}
62+
5463
/**
5564
* Get the minimum value for the merit measure
5665
*
@@ -68,4 +77,22 @@ public double getMinMerit() {
6877
public void setMinMerit(Double minMerit) {
6978
this.minMerit = minMerit;
7079
}
80+
81+
/**
82+
* Sets the minimum value for the merit measure
83+
*
84+
* @param minMerit minimum value for merit
85+
*/
86+
public void setMinMerit(Integer minMerit) {
87+
this.minMerit = minMerit;
88+
}
89+
90+
/*
91+
* (non-Javadoc)
92+
*
93+
* @see java.lang.Object#toString()
94+
*/
95+
public String toString() {
96+
return "minConf=" + this.minConf + " minMerit=" + this.minMerit;
97+
}
7198
}

src/main/java/lac/algorithms/adt/Rule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public double getPessimisticErrorEstimate() {
117117
* @see lac.algorithms.Rule#toString()
118118
*/
119119
public String toString() {
120-
return super.toString() + " hits: " + this.hits + " misses: " + this.misses + " per; "
120+
return super.toString() + " hits: " + this.hits + " misses: " + this.misses + " per: "
121121
+ this.getPessimisticErrorEstimate();
122122
}
123123

src/main/java/lac/algorithms/cba/Config.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ public class Config extends lac.algorithms.Config {
3131
*/
3232
private double minConf = 0.5;
3333

34-
/**
35-
* Maximum number of rules
36-
*/
37-
private long limitRules = 80000;
38-
3934
/**
4035
* Set the value of minimum support
4136
*
@@ -72,24 +67,6 @@ public void setMinConf(Integer minConf) {
7267
this.minConf = minConf;
7368
}
7469

75-
/**
76-
* Set the limit of rules to be extracted
77-
*
78-
* @param limitRules to be extracted
79-
*/
80-
public void setLimitRules(Long limitRules) {
81-
this.limitRules = limitRules <= 0 ? Long.MAX_VALUE : limitRules;
82-
}
83-
84-
/**
85-
* Set the limit of rules to be extracted
86-
*
87-
* @param limitRules to be extracted
88-
*/
89-
public void setLimitRules(Integer limitRules) {
90-
this.setLimitRules(new Long(limitRules));
91-
}
92-
9370
/**
9471
* Minimum value of support for the rules
9572
*
@@ -114,6 +91,6 @@ public double getMinConf() {
11491
* @see java.lang.Object#toString()
11592
*/
11693
public String toString() {
117-
return "minSup=" + this.minSup + " minConf=" + this.minConf + " limitRules=" + this.limitRules;
94+
return "minSup=" + this.minSup + " minConf=" + this.minConf;
11895
}
11996
}

src/main/java/lac/algorithms/cba/Rule.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ public Rule() {
8787
*/
8888
public Rule(short klass) {
8989
super(klass);
90+
this.klassesCovered = new HashMap<Short, Long>();
91+
this.replace = new ArrayList<Replace>();
92+
this.time = System.currentTimeMillis();
9093
this.pessimisticErrorRate = 0;
9194
this.hits = 0;
9295
this.misses = 0;
@@ -115,7 +118,7 @@ public double getPessimisticErrorRate() {
115118
* rule
116119
*
117120
* @param a
118-
* @return
121+
* @return true if is subset, false otherwise
119122
*/
120123
public boolean isSubset(Rule a) {
121124
if (this.klass != a.getKlass())

src/main/java/lac/algorithms/cmar/Config.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,24 @@ public void setMinSup(Double minSup) {
4747
this.minSup = minSup;
4848
}
4949

50+
/**
51+
* Set the minimum confidence for the rules
52+
*
53+
* @param minConf minimum value for confidence
54+
*/
55+
public void setMinConf(Integer minConf) {
56+
this.minConf = minConf;
57+
}
58+
59+
/**
60+
* Set the minimum support for the rules
61+
*
62+
* @param minSup minimum value for support
63+
*/
64+
public void setMinSup(Integer minSup) {
65+
this.minSup = minSup;
66+
}
67+
5068
/**
5169
* Set the minimum confidence for the rules
5270
*

src/main/java/lac/algorithms/cmar/FPGrowth.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ protected void generateRules(short[] antecedent, int antecedentLength, long supp
373373
Rule rule = new Rule(itemsetOutputBuffer, entry.getKey());
374374
rule.setSupportAntecedent(support);
375375
rule.setSupportRule(entry.getValue());
376-
rule.setSupportConsequent(dataset.getFrequencyByKlass().get(rule.getKlass()));
376+
rule.setSupportKlass(dataset.getFrequencyByKlass().get(rule.getKlass()));
377377

378378
if (rule.getSupportRule() >= this.minSupportRelative && rule.getConfidence() >= this.minConf)
379379
rules.add(rule);

0 commit comments

Comments
 (0)