Skip to content

Commit 448543d

Browse files
vvittis@isc.tuc.grvvittis@isc.tuc.gr
authored andcommitted
Base Learner Proposition: No VDDM , Yes: SVFDT-II
1 parent a728e97 commit 448543d

File tree

3 files changed

+29
-44
lines changed

3 files changed

+29
-44
lines changed

src/main/java/DistributedLearning.java

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -286,65 +286,42 @@ public void flatMap(Tuple3<String, Integer, Integer> input_stream, Collector<Tup
286286
// WARNING PHASE
287287
if (!empty_background_state.value()) {
288288
HoeffdingTree background_hoeffdingTree = background_hoeffdingTreeValueState.value();
289-
background_hoeffdingTree.TestHoeffdingTree(background_hoeffdingTree.root, features, 0);
290-
background_hoeffdingTree.UpdateHoeffdingTree(background_hoeffdingTree.root, features, instance_weight);
289+
for (int i = 0; i < instance_weight; i++) {
290+
background_hoeffdingTree.UpdateHoeffdingTree(background_hoeffdingTree.root, features, instance_weight);
291+
}
291292
background_hoeffdingTreeValueState.update(background_hoeffdingTree);
292-
// System.out.println(" "+instance_id+" "+background_hoeffdingTree.getAccuracy());
293-
collector.collect(new Tuple6<>(instance_id, prediction, -1, purpose_id, background_hoeffdingTree.getErrorRate(), 0));
294293
} else if (empty_background_state.value()) {
295294
// System.out.println("===================================Warning Phase===================================");
296-
System.out.println("Background Tree " + instance_id + " Just Created ");
295+
// System.out.println("Background Tree " + instance_id + " Just Created ");
297296
empty_background_state.update(false);
298297
// Warning Signal. Create & Train the Background Tree
299298
HoeffdingTree background_hoeffdingTree = new HoeffdingTree();
300-
background_hoeffdingTree.NEW_CreateHoeffdingTree(2, 2, 200, 0.000001, 0.05, this.combination_function, hoeffding_tree_id, age_of_maturity_input);
299+
background_hoeffdingTree.NEW_CreateHoeffdingTree(7, 9, 200, 0.0001, 0.05, this.combination_function, hoeffding_tree_id, 1);
301300
// background_hoeffdingTree.print_m_features();
302301
background_hoeffdingTreeValueState.update(background_hoeffdingTree);
303-
collector.collect(new Tuple6<>(instance_id, prediction, -1, purpose_id, background_hoeffdingTree.getErrorRate(), 0));
304-
305302
}
306-
} else if ((current_stream_status == 1 || current_stream_status == 2) && updated_stream_status == 2) {
303+
} else if (current_stream_status == 1 && updated_stream_status == 0) {
307304
// System.out.println("DS Signal: instance id " + instance_id);
308305
if (current_signal == 2) {
309306
// System.out.println("=============================Stable Phase/ Drift===================================");
310307
// System.out.println("Stable phase after a Drift Signal");
311-
// System.out.println("Do the Switch: " + instance_id + " Background Tree taking over "+ht.getAccuracy());
308+
System.out.println("Do the Switch: " + instance_id + "Background Tree taking over");
312309
// Drift Signal. Do the Switch
313310
HoeffdingTree background_tree = background_hoeffdingTreeValueState.value();
314-
background_tree.TestHoeffdingTree(background_tree.root, features, 0);
315-
background_tree.UpdateHoeffdingTree(background_tree.root, features, instance_weight);
316-
background_hoeffdingTreeValueState.update(background_tree);
317-
collector.collect(new Tuple6<>(instance_id, prediction, -1, purpose_id, background_tree.getErrorRate(), 0));
318-
319-
if (current_stream_status == 1) {
320-
System.out.println("Pending for the Switch: " + hoeffding_tree_id + " => " + instance_id + " Background Tree taking over " + ht.getAccuracy() + " => " + background_tree.getAccuracy());
321-
}
322-
// System.out.println("Size "+ ht.SizeHT(ht.root));
323-
// System.out.println("Counter "+ ht.counter);
324-
if (background_tree.getAccuracy() > ht.getAccuracy()) {
325-
System.out.println("Do the Switch: " + hoeffding_tree_id + " => " + instance_id + " Background Tree taking over " + ht.getAccuracy() + " => " + background_tree.getAccuracy());
326-
ht.RemoveHoeffdingTree();
327-
hoeffdingTreeValueState.update(background_tree);
328-
ht = hoeffdingTreeValueState.value();
329-
System.out.println(ht.getAccuracy() + " " + ht.getErrorRate());
330-
empty_background_state.update(true);
331-
// System.out.println("Making the switch and resetting the Drift Detector");
332-
//RESET EVERYTHING
333-
conceptDriftDetector.ResetConceptDrift();
334-
}
335-
collector.collect(new Tuple6<>(instance_id, prediction, -1, purpose_id, background_tree.getErrorRate(), 0));
336-
337-
}
338-
} else if (current_stream_status == 1 && updated_stream_status == 0) {
339-
if (current_signal == -1) {
311+
ht.RemoveHoeffdingTree();
312+
hoeffdingTreeValueState.update(background_tree);
313+
empty_background_state.update(true);
314+
// System.out.println("Making the switch and resetting the Drift Detector");
315+
//RESET EVERYTHING
316+
conceptDriftDetector.ResetConceptDrift();
317+
} else if (current_signal == -1) {
340318
// System.out.println("=========================Stable Phase/ False Alarm=================================");
341-
System.out.println("Stable phase after a false alarm");
319+
// System.out.println("Stable phase after a false alarm");
342320
// System.out.println("FAS False Alarm Signal: instance id " + instance_id);
343321
HoeffdingTree background_tree = background_hoeffdingTreeValueState.value();
344322
background_tree.RemoveHoeffdingTree();
345323
background_hoeffdingTreeValueState.clear();
346324
empty_background_state.update(true);
347-
348325
}
349326
//System.out.println("Training HT with id " + hoeffding_tree_id + " which has error-rate " + ht.getErrorRate() + " predicts " + prediction + " for the instance with id " + instance_id + " while the true label is " + true_label);
350327
}
@@ -372,8 +349,8 @@ public void flatMap(Tuple3<String, Integer, Integer> input_stream, Collector<Tup
372349
} else if (instance_id == -1 && true_label == -1 && purpose_id == -1) {
373350
HoeffdingTree ht = hoeffdingTreeValueState.value();
374351
int size = ht.SizeHT(ht.root);
375-
376-
System.out.print(size + "\t" + ht.getAccuracy() + "\t");
352+
int number_of_splits = ht.getNumberOfSplits(ht.root);
353+
System.out.print(size + "\t" + ht.getAccuracy() + "\t"+number_of_splits);
377354
// System.out.println("Accuracy : " + ht.getAccuracy());
378355

379356
System.out.println("End of Stream message " + hoeffding_tree_id);

src/main/java/HoeffdingTree/HoeffdingTree.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,15 @@ public void UpdateHoeffdingTree(Node node, String[] input, int weight) {
131131
// System.out.println(statistics_entropy_history[2] + " => " + Math.sqrt(statistics_entropy_history[1] / (statistics_entropy_history[2] - 2)));
132132
// System.out.println(statistics_ig_history[2] + " => " + Math.sqrt(statistics_ig_history[1] / (statistics_ig_history[2] - 2)));
133133
}
134+
}else {
135+
Node updatedNode = node.TraverseTree(node, input);
136+
node.InsertNewSample(updatedNode, input, weight);
134137
}
135138

136139
}
137-
140+
public int getNumberOfSplits(Node node){
141+
return node.getSplitting_counter();
142+
}
138143

139144
public int SizeHT(Node node) {
140145
return node.countNode(node);

src/main/java/HoeffdingTree/Node.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Node implements Serializable {
3333
public Integer nmin; // Keep tracking the number of samples seen
3434
public Integer nmin_last_check; // Number of instances from last check
3535
public ArrayList<HashMap<Integer, ArrayList<Double>>> statistics = new ArrayList<>(); // number of values for each column
36-
36+
public Integer splitting_counter;
3737
/*
3838
* || feature 1 || ... || feature N || <- ArrayList <
3939
* || ------------------------------------------------------------- ||
@@ -67,7 +67,9 @@ public Integer getNmin() {
6767
return this.nmin;
6868
}
6969

70-
70+
public Integer getSplitting_counter(){
71+
return this.splitting_counter;
72+
}
7173
public int countNode(Node root) {
7274

7375
//base case
@@ -100,6 +102,7 @@ public int countNode(Node root) {
100102
this.rightNode = null;
101103
this.splitAttr = null;
102104
this.splitValue = null;
105+
this.splitting_counter=0;
103106
this.delta = delta;
104107
this.max_examples_seen = max_examples_seen;
105108
this.m_features = m_features;
@@ -310,7 +313,7 @@ public double[] AttemptSplit(Node node, String[] sample, int weight, double[] st
310313
// true; - for testing
311314
boolean svfdt_ii_constraints = (entropy > 0) || (ig > 0);
312315
if (svfdt_ii_constraints) {
313-
316+
this.splitting_counter ++;
314317
double[] values = {G[0][0], G[1][0], G[2][0],G[3][0],G[4][0]};
315318

316319
SplitFunction(node, values);

0 commit comments

Comments
 (0)