/** * Main method for testing this class. * * @param args the commandline options, use "-h" for help */ public static void main(String[] args) { runClusterer(new FilteredClusterer(), args); } }
@Override public void setFilter(Filter filter) { super.setFilter(filter); if (!(filter instanceof PreconstructedFilter)) { throw new IllegalArgumentException( "The filter must be a Preconstructed one!"); } else if (!((PreconstructedFilter) filter).isConstructed()) { throw new IllegalArgumentException("PreconstructedFilter: " + filter.getClass().getName() + " has not been initialized!"); } m_FilteredInstances = filter.getOutputFormat(); }
/** * Output a representation of this clusterer. * * @return a representation of this clusterer */ @Override public String toString() { String result; if (m_FilteredInstances == null) { result = "FilteredClusterer: No model built yet."; } else { result = "FilteredClusterer using " + getClustererSpec() + " on data filtered through " + getFilterSpec() + "\n\nFiltered Header\n" + m_FilteredInstances.toString() + "\n\nClusterer Model\n" + m_Clusterer.toString(); } return result; }
filters = ((FilteredClusterer) c).getFilter(); cList.add((Canopy) ((FilteredClusterer) c).getClusterer());
/** * Gets the filter specification string, which contains the class name of the * filter and any options to the filter. * * @return the filter string. */ protected String getFilterSpec() { String result; Filter filter; filter = getFilter(); result = filter.getClass().getName(); if (filter instanceof OptionHandler) { result += " " + Utils.joinOptions(((OptionHandler) filter).getOptions()); } return result; }
/** Creates a default FilteredClusterer */ public Clusterer getClusterer() { return new FilteredClusterer(); }
/** * Build the clusterer on the filtered data. * * @param data the training data * @throws Exception if the clusterer could not be built successfully */ @Override public void buildClusterer(Instances data) throws Exception { if (m_Clusterer == null) { throw new Exception("No base clusterer has been set!"); } // remove instances with missing class if (data.classIndex() > -1) { data = new Instances(data); data.deleteWithMissingClass(); } m_Filter.setInputFormat(data); // filter capabilities are checked here data = Filter.useFilter(data, m_Filter); // can clusterer handle the data? getClusterer().getCapabilities().testWithFail(data); m_FilteredInstances = data.stringFreeStructure(); m_Clusterer.buildClusterer(data); }
/** * Gets the current settings of the clusterer. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.addElement("-F"); result.addElement(getFilterSpec()); Collections.addAll(result, super.getOptions()); return result.toArray(new String[result.size()]); }
/** * Returns graph describing the clusterer (if possible). * * @return the graph of the clusterer in dotty format * @throws Exception if the clusterer cannot be graphed */ public String graph() throws Exception { if (m_Clusterer instanceof Drawable) return ((Drawable) m_Clusterer).graph(); else throw new Exception( "Clusterer: " + getClustererSpec() + " cannot be graphed"); }
/** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration<Option> listOptions() { Vector<Option> result = new Vector<Option>(); result.addElement(new Option( "\tFull class name of filter to use, followed\n" + "\tby filter options.\n" + "\teg: \"weka.filters.unsupervised.attribute.Remove -V -R 1,2\"\n" + "(default: " + defaultFilterString() + ")", "F", 1, "-F <filter specification>")); result.addAll(Collections.list(super.listOptions())); return result.elements(); }
/** * Gets the filter specification string, which contains the class name of the * filter and any options to the filter. * * @return the filter string. */ protected String getFilterSpec() { String result; Filter filter; filter = getFilter(); result = filter.getClass().getName(); if (filter instanceof OptionHandler) { result += " " + Utils.joinOptions(((OptionHandler) filter).getOptions()); } return result; }
/** Creates a default FilteredClusterer */ public Clusterer getClusterer() { return new FilteredClusterer(); }
/** * Build the clusterer on the filtered data. * * @param data the training data * @throws Exception if the clusterer could not be built successfully */ @Override public void buildClusterer(Instances data) throws Exception { if (m_Clusterer == null) { throw new Exception("No base clusterer has been set!"); } // remove instances with missing class if (data.classIndex() > -1) { data = new Instances(data); data.deleteWithMissingClass(); } m_Filter.setInputFormat(data); // filter capabilities are checked here data = Filter.useFilter(data, m_Filter); // can clusterer handle the data? getClusterer().getCapabilities().testWithFail(data); m_FilteredInstances = data.stringFreeStructure(); m_Clusterer.buildClusterer(data); }
/** * Gets the current settings of the clusterer. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.addElement("-F"); result.addElement(getFilterSpec()); Collections.addAll(result, super.getOptions()); return result.toArray(new String[result.size()]); }
/** * Returns graph describing the clusterer (if possible). * * @return the graph of the clusterer in dotty format * @throws Exception if the clusterer cannot be graphed */ public String graph() throws Exception { if (m_Clusterer instanceof Drawable) return ((Drawable) m_Clusterer).graph(); else throw new Exception( "Clusterer: " + getClustererSpec() + " cannot be graphed"); }
/** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration<Option> listOptions() { Vector<Option> result = new Vector<Option>(); result.addElement(new Option( "\tFull class name of filter to use, followed\n" + "\tby filter options.\n" + "\teg: \"weka.filters.unsupervised.attribute.Remove -V -R 1,2\"\n" + "(default: " + defaultFilterString() + ")", "F", 1, "-F <filter specification>")); result.addAll(Collections.list(super.listOptions())); return result.elements(); }
/** * Main method for testing this class. * * @param args the commandline options, use "-h" for help */ public static void main(String[] args) { runClusterer(new FilteredClusterer(), args); } }
/** * Returns default capabilities of the clusterer. * * @return the capabilities of this clusterer */ @Override public Capabilities getCapabilities() { Capabilities result; if (getFilter() == null) { result = super.getCapabilities(); result.disableAll(); result.enable(Capability.NO_CLASS); } else { result = getFilter().getCapabilities(); } // set dependencies for (Capability cap : Capability.values()) { result.enableDependency(cap); } return result; }
/** * Output a representation of this clusterer. * * @return a representation of this clusterer */ @Override public String toString() { String result; if (m_FilteredInstances == null) { result = "FilteredClusterer: No model built yet."; } else { result = "FilteredClusterer using " + getClustererSpec() + " on data filtered through " + getFilterSpec() + "\n\nFiltered Header\n" + m_FilteredInstances.toString() + "\n\nClusterer Model\n" + m_Clusterer.toString(); } return result; }