00001
00002
00003
00004 package edu.tum.cs.bayesnets.core;
00005
00006 import edu.tum.cs.clustering.ClusterNamer;
00007 import weka.clusterers.Clusterer;
00008 import weka.core.Instance;
00009
00014 public class ClustererDiscretizationFilter implements DiscretizationFilter {
00015
00019 protected String[] outputValues;
00023 protected Clusterer clusterer;
00024
00032 public <C extends Clusterer> ClustererDiscretizationFilter(C clusterer, ClusterNamer<? super C> namer) throws Exception {
00033 this.clusterer = clusterer;
00034 outputValues = namer.getNames(clusterer);
00035 }
00036
00037
00038
00039
00040 public String[] getOutputValues() {
00041 return outputValues;
00042 }
00043
00044
00045
00046
00047 public String getValueForContinuous(double continuous) {
00048 Instance inst = new Instance(1);
00049 inst.setValue(0, continuous);
00050 try {
00051 int cluster = clusterer.clusterInstance(inst);
00052 return outputValues[cluster];
00053 } catch (Exception e) {
00054 e.printStackTrace();
00055 return null;
00056 }
00057 }
00058
00059
00060
00061
00062 public void addOutputValue(String outputValue) {
00063
00064 throw new IllegalArgumentException("Cannot add outputValue for clusterer domains!");
00065 }
00066
00067
00068
00069
00070 public double getExampleValue(int bin) {
00071 throw new IllegalArgumentException("Cannot sample cluster values!");
00072 }
00073
00074
00075
00076
00077 public double[] getIntervals(int bin) {
00078 throw new IllegalArgumentException("Cannot get cluster intervals!");
00079 }
00080 }