-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProductivitySplitClustererTest.java
101 lines (73 loc) · 3.71 KB
/
ProductivitySplitClustererTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package moa.clusterers.threshold;
import com.yahoo.labs.samoa.instances.Instance;
import junit.framework.TestCase;
import moa.cluster.Clustering;
import moa.cluster.ProductivityThresholdCluster;
import moa.streams.ArffFileStream;
public class ProductivitySplitClustererTest extends TestCase {
public ProductivitySplitClustererTest() {
super();
}
public ProductivitySplitClustererTest(String name) {
super(name);
}
private ArffFileStream dataStream;
private String dataSetFileName = "test_clusterer_no_timestamp.arff";
private int effIndex = 2; // note that the class index starts with 0
private int sizeIndex = 1;
protected void setUp() throws Exception {
super.setUp();
dataStream = new ArffFileStream(dataSetFileName, effIndex);
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testGetInclusionProbability() {
ProductivitySplitClusterer clusterer = new ProductivitySplitClusterer();
clusterer.prodThresholdsOption.setValue("1.0;2.0");
clusterer.effortAttIndexOption.setValue(effIndex);
clusterer.sizeAttIndexOption.setValue(sizeIndex);
clusterer.resetLearningImpl();
assertEquals(2, clusterer.getNumberProductivityThresholds());
assertEquals(1.0, clusterer.getProductivityThreshold(0));
assertEquals(2.0, clusterer.getProductivityThreshold(1));
Clustering clusters = clusterer.getClusteringResult();
assertEquals(3, clusters.getClustering().size());
assertEquals(Double.MIN_VALUE, ((ProductivityThresholdCluster) clusters.get(0)).getLeftThreshold());
assertEquals(1.0, ((ProductivityThresholdCluster) clusters.get(0)).getRightThreshold());
assertEquals(1.0, ((ProductivityThresholdCluster) clusters.get(1)).getLeftThreshold());
assertEquals(2.0, ((ProductivityThresholdCluster) clusters.get(1)).getRightThreshold());
assertEquals(2.0, ((ProductivityThresholdCluster) clusters.get(2)).getLeftThreshold());
assertEquals(Double.MAX_VALUE, ((ProductivityThresholdCluster) clusters.get(2)).getRightThreshold());
Instance inst = dataStream.nextInstance().instance; // 2,0,1
assertEquals(1.0, inst.value(effIndex));
assertEquals(0.0, inst.value(sizeIndex));
assertEquals(0.0, clusters.get(0).getInclusionProbability(inst));
assertEquals(0.0, clusters.get(1).getInclusionProbability(inst));
assertEquals(1.0, clusters.get(2).getInclusionProbability(inst));
inst = dataStream.nextInstance().instance; // 4,6,5
assertEquals(5.0, inst.value(effIndex));
assertEquals(6.0, inst.value(sizeIndex));
assertEquals(1.0, clusters.get(0).getInclusionProbability(inst));
assertEquals(0.0, clusters.get(1).getInclusionProbability(inst));
assertEquals(0.0, clusters.get(2).getInclusionProbability(inst));
inst = dataStream.nextInstance().instance; // 4,5,6
assertEquals(6.0, inst.value(effIndex));
assertEquals(5.0, inst.value(sizeIndex));
assertEquals(0.0, clusters.get(0).getInclusionProbability(inst));
assertEquals(1.0, clusters.get(1).getInclusionProbability(inst));
assertEquals(0.0, clusters.get(2).getInclusionProbability(inst));
inst = dataStream.nextInstance().instance; // 4,5,15
assertEquals(15.0, inst.value(effIndex));
assertEquals(5.0, inst.value(sizeIndex));
assertEquals(0.0, clusters.get(0).getInclusionProbability(inst));
assertEquals(0.0, clusters.get(1).getInclusionProbability(inst));
assertEquals(1.0, clusters.get(2).getInclusionProbability(inst));
inst = dataStream.nextInstance().instance; // 1,1,1
assertEquals(1.0, inst.value(effIndex));
assertEquals(1.0, inst.value(sizeIndex));
assertEquals(1.0, clusters.get(0).getInclusionProbability(inst));
assertEquals(0.0, clusters.get(1).getInclusionProbability(inst));
assertEquals(0.0, clusters.get(2).getInclusionProbability(inst));
}
}