00001 package edu.tum.cs.clustering.multidim;
00002
00003 import java.lang.reflect.InvocationTargetException;
00004
00005 import weka.core.Attribute;
00006 import weka.core.FastVector;
00007 import weka.core.Instance;
00008 import weka.core.Instances;
00009
00016 public class MultiDimClusterer<TClusterer extends weka.clusterers.Clusterer> {
00017 protected Attribute[] attrs;
00018 protected TClusterer clusterer;
00019 protected Instances instances;
00020 protected int dimensions;
00021
00022 public MultiDimClusterer(TClusterer clusterer, int dimensions) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
00023 this.clusterer = clusterer;
00024 FastVector attribs = new FastVector(dimensions);
00025 for(int i = 0; i < dimensions; i++)
00026 attribs.addElement(new Attribute(String.format("v%d", i)));
00027 instances = new Instances("foo", attribs, 100);
00028 }
00029
00030 public void addInstance(double[] v) {
00031
00032
00033
00034 instances.add(new Instance(1.0, v));
00035 }
00036
00037 public void buildClusterer() throws Exception {
00038 clusterer.buildClusterer(instances);
00039 }
00040
00041 public int classify(double[] v) throws Exception {
00042 Instance inst = new Instance(1.0, v);
00043 return clusterer.clusterInstance(inst);
00044 }
00045
00046 public TClusterer getWekaClusterer() {
00047 return clusterer;
00048 }
00049 }