00001 package edu.tum.cs.clustering; 00002 00003 import weka.core.Attribute; 00004 import weka.core.FastVector; 00005 import weka.core.Instance; 00006 import weka.core.Instances; 00007 00014 public class BasicClusterer<TClusterer extends weka.clusterers.Clusterer> { 00015 protected Attribute attrValue; 00016 protected TClusterer clusterer; 00017 protected Instances instances; 00018 00019 public BasicClusterer(TClusterer clusterer) { 00020 attrValue = new Attribute("value"); 00021 FastVector attribs = new FastVector(1); 00022 attribs.addElement(attrValue); 00023 instances = new Instances("foo", attribs, 100); 00024 this.clusterer = clusterer; 00025 } 00026 00027 public void addInstance(double value) { 00028 Instance inst = new Instance(1); 00029 inst.setValue(attrValue, value); 00030 instances.add(inst); 00031 } 00032 00033 public void buildClusterer() throws Exception { 00034 clusterer.buildClusterer(instances); 00035 } 00036 00037 public int classify(double value) throws Exception { 00038 Instance inst = new Instance(1); 00039 inst.setValue(attrValue, value); 00040 return clusterer.clusterInstance(inst); 00041 } 00042 00043 public TClusterer getWekaClusterer() { 00044 return clusterer; 00045 } 00046 }