package classifier; import de.tu_darmstadt.tk.SmartHomeNetworkSim.core.Packet; import weka.clusterers.EM; import weka.core.Instance; import weka.core.Instances; /** * Expectation Maximization Clustering Approach * @author Andreas T. Meyer-Berg */ public class EMClustering extends BasicPacketClassifier { /** * EM cluster which is used */ private EM clusterer; /** * Initialize the clusterer */ public EMClustering() { clusterer = new EM(); } @Override public void trainModel(Instances instances) { try { clusterer.buildClusterer(instances); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public double classifyInstance(Instance instance, Packet origin) throws Exception { /** * Id of the closest cluster */ int x = clusterer.clusterInstance(instance); /* System.out.println(origin.getTextualRepresentation()+": cluster: "+x+" Dens: "+clusterer.logDensityForInstance(instance)+" joined: "); double[] joined = clusterer.logJointDensitiesForInstance(instance); for(int i = 0;i