00001 /* 00002 * Created on Oct 26, 2007 00003 */ 00004 package edu.tum.cs.bayesnets.core; 00005 00006 import weka.clusterers.Clusterer; 00007 import edu.ksu.cis.bnj.ver3.core.Discrete; 00008 import edu.tum.cs.clustering.ClusterNamer; 00009 00015 public class Discretized extends Discrete { 00019 protected DiscretizationFilter discretizationFilter; 00023 Discrete discrete; 00024 00030 public <C extends Clusterer> Discretized(C clusterer, ClusterNamer<? super C> namer) throws Exception { 00031 setDiscretizationFilter(new ClustererDiscretizationFilter(clusterer, namer)); 00032 } 00033 00039 public Discretized(DiscretizationFilter filter) { 00040 setDiscretizationFilter(filter); 00041 } 00042 00043 public Discretized() { 00044 setDiscretizationFilter(new DiscretizationFilter.Default(new double[0])); 00045 } 00046 00051 public DiscretizationFilter getDiscretizationFilter() { 00052 return discretizationFilter; 00053 } 00054 00059 public void setDiscretizationFilter(DiscretizationFilter filter) { 00060 discretizationFilter = filter; 00061 if (filter != null) 00062 discrete=new Discrete(discretizationFilter.getOutputValues()); 00063 } 00064 00070 public String getNameFromContinuous(double value) { 00071 return discretizationFilter.getValueForContinuous(value); 00072 } 00073 00080 public void addName(String outcome) { 00081 discretizationFilter.addOutputValue(outcome); 00082 setDiscretizationFilter(discretizationFilter); 00083 } 00084 00091 public int findName(String outcome) { 00092 return discrete.findName(outcome); 00093 } 00094 00101 public String getName(int o) { 00102 return discrete.getName(o); 00103 } 00104 00110 public int getOrder() { 00111 return discrete.getOrder(); 00112 } 00113 00114 /* (non-Javadoc) 00115 * @see java.lang.Object#toString() 00116 */ 00117 public String toString() { 00118 if (getOrder()<1) 00119 return "{empty domain}"; 00120 StringBuffer sb = new StringBuffer("{"+getName(0)); 00121 for (int i=1; i<getOrder(); i++) { 00122 sb.append(", ").append(getName(i)); 00123 } 00124 sb.append("}"); 00125 return sb.toString(); 00126 } 00127 00133 public double[] getIntervals(int bin) { 00134 return discretizationFilter.getIntervals(bin); 00135 } 00136 00142 public double getExampleValue(int bin) { 00143 return discretizationFilter.getExampleValue(bin); 00144 } 00145 }