|
@@ -13,7 +13,6 @@ import weka.core.Attribute;
|
|
|
import weka.core.DenseInstance;
|
|
|
import weka.core.Instance;
|
|
|
import weka.core.Instances;
|
|
|
-import weka.core.NominalAttributeInfo;
|
|
|
|
|
|
/**
|
|
|
* Unsupervised Example - maybe Clustering
|
|
@@ -98,17 +97,6 @@ public class UnsupervisedAnomalyDetectionExample2 implements PacketSniffer {
|
|
|
|
|
|
@Override
|
|
|
public void processPackets(HashMap<Link, LinkedList<Packet>> packets) {
|
|
|
- if(training && !packets.entrySet().isEmpty() && !packets.entrySet().iterator().next().getValue().isEmpty() && packets.entrySet().iterator().next().getValue().getFirst().getTimestamp()>10000) {
|
|
|
- training = false;
|
|
|
- // Build Clusterer
|
|
|
- try {
|
|
|
- finishDataCollection();
|
|
|
- } catch (Exception e) {
|
|
|
- System.out.println("Clustering failed");
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if(training)
|
|
|
try {
|
|
|
training(packets);
|
|
@@ -336,11 +324,20 @@ public class UnsupervisedAnomalyDetectionExample2 implements PacketSniffer {
|
|
|
|
|
|
@Override
|
|
|
public void setMode(boolean testing) {
|
|
|
- mode = testing;
|
|
|
+ training = !testing;
|
|
|
+ if(testing) {
|
|
|
+ // Build Clusterer
|
|
|
+ try {
|
|
|
+ finishDataCollection();
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.out.println("Clustering failed");
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public boolean getMode() {
|
|
|
- return mode;
|
|
|
+ return !training;
|
|
|
}
|
|
|
}
|