/** * Builds a string listing the attribute values in a specified range of * indices, separated by commas and enclosed in brackets. * * @param instance the instance to print the values from * @param attRange the range of the attributes to list * @return a string listing values of the attributes in the range */ private static String attributeValuesString(Instance instance, Range attRange) { StringBuffer text = new StringBuffer(); if (attRange != null) { boolean firstOutput = true; attRange.setUpper(instance.numAttributes() - 1); for (int i = 0; i < instance.numAttributes(); i++) { if (attRange.isInRange(i)) { if (firstOutput) { text.append("("); } else { text.append(","); } text.append(instance.toString(i)); firstOutput = false; } } if (!firstOutput) { text.append(")"); } } return text.toString(); }
/** * Swaps the keys for dataset and result. */ protected void swapDatasetKeyAndResultKey() { int[] tmpSelected; Range tmpRange; // lists tmpSelected = m_DatasetKeyList.getSelectedIndices(); m_DatasetKeyList.setSelectedIndices(m_ResultKeyList.getSelectedIndices()); m_ResultKeyList.setSelectedIndices(tmpSelected); // tester tmpRange = m_TTester.getDatasetKeyColumns(); m_TTester.setDatasetKeyColumns(m_TTester.getResultsetKeyColumns()); m_TTester.setResultsetKeyColumns(tmpRange); setTTester(); }
/** * Builds a string listing the attribute values in a specified range of indices, * separated by commas and enclosed in brackets. * * @param instance the instance to print the values from * @param attRange the range of the attributes to list * @return a string listing values of the attributes in the range */ private static String attributeValuesString(Instance instance, Range attRange) { StringBuffer text = new StringBuffer(); if (attRange != null) { boolean firstOutput = true; attRange.setUpper(instance.numAttributes() - 1); for (int i=0; i<instance.numAttributes(); i++) if (attRange.isInRange(i)) { if (firstOutput) text.append("("); else text.append(","); text.append(instance.toString(i)); firstOutput = false; } if (!firstOutput) text.append(")"); } return text.toString(); }
/** * performs the actual test * * @param filters the filters to use * @param ranges the ranges to use * @param remove whether to remove unused attributes or not * @return the processed dataset * @throws Exception if apllying of filter fails */ protected Instances applyFilter(Filter[] filters, Range[] ranges, boolean remove) throws Exception { PartitionedMultiFilter filter; Instances result; filter = (PartitionedMultiFilter) getFilter(); filter.setFilters(filters); filter.setRanges(ranges); filter.setRemoveUnused(remove); filter.setInputFormat(m_Instances); result = Filter.useFilter(m_Instances, filter); return result; }
/** * tests two filters with disjoint ranges */ public void testDisjoint() { Instances result = null; m_Instances.setClassIndex(2); try { result = applyFilter( new Filter[]{new AllFilter(), new AllFilter()}, new Range[]{new Range("1-2"),new Range("4-5")}, false); } catch (Exception e) { fail("Problem applying the filter: " + e); } assertEquals(m_Instances.numInstances(), result.numInstances()); assertEquals(m_Instances.numAttributes(), result.numAttributes()); }
/** * tests two filters with disjoint ranges and removing the unused attributes */ public void testDisjointRemoveUnused() { Instances result = null; m_Instances.setClassIndex(2); try { result = applyFilter( new Filter[]{new AllFilter(), new AllFilter()}, new Range[]{new Range("1-2"),new Range("5")}, true); } catch (Exception e) { fail("Problem applying the filter: " + e); } assertEquals(m_Instances.numInstances(), result.numInstances()); assertEquals(m_Instances.numAttributes() - 1, result.numAttributes()); }
/** * tests two filters with overlapping ranges */ public void testOverlapping() { Instances result = null; m_Instances.setClassIndex(2); try { result = applyFilter( new Filter[]{new AllFilter(), new AllFilter()}, new Range[]{new Range("1,2,4"),new Range("2,4")}, false); } catch (Exception e) { fail("Problem applying the filter: " + e); } assertEquals(m_Instances.numInstances(), result.numInstances()); assertEquals(m_Instances.numAttributes() + 2, result.numAttributes()); }
/** * tests two filters with overlapping ranges and removing the unused attributes */ public void testOverlappingRemoveUnused() { Instances result = null; m_Instances.setClassIndex(2); try { result = applyFilter( new Filter[]{new AllFilter(), new AllFilter()}, new Range[]{new Range("1,2,4"),new Range("2,4")}, true); } catch (Exception e) { fail("Problem applying the filter: " + e); } assertEquals(m_Instances.numInstances(), result.numInstances()); assertEquals(m_Instances.numAttributes() + 1, result.numAttributes()); }
/** * Constructor */ public GreedyStepwise() { m_threshold = -Double.MAX_VALUE; m_doneRanking = false; m_startRange = new Range(); m_starting = null; resetOptions(); }
/** * Resets stuff to default values */ protected void resetOptions() { m_starting = null; m_startRange = new Range(); m_attributeList = null; m_attributeMerit = null; m_threshold = -Double.MAX_VALUE; }
/** * Reset options to default values */ protected void resetOptions() { m_maxStale = 5; m_searchDirection = SELECTION_FORWARD; m_starting = null; m_startRange = new Range(); m_classIndex = -1; m_totalEvals = 0; m_cacheSize = 1; m_debug = false; }
/** * Prints the classifiers. * * @return a string representation of the classifier */ public String toString() { if (m_Classifiers == null) { return "MultiClassClassifier: No model built yet."; } StringBuffer text = new StringBuffer(); text.append("MultiClassClassifier\n\n"); for (int i = 0; i < m_Classifiers.length; i++) { text.append("Classifier ").append(i + 1); if (m_Classifiers[i] != null) { if ((m_ClassFilters != null) && (m_ClassFilters[i] != null)) { if (m_ClassFilters[i] instanceof RemoveWithValues) { Range range = new Range(((RemoveWithValues)m_ClassFilters[i]) .getNominalIndices()); range.setUpper(m_ClassAttribute.numValues()); int[] pair = range.getSelection(); text.append(", " + (pair[0]+1) + " vs " + (pair[1]+1)); } else if (m_ClassFilters[i] instanceof MakeIndicator) { text.append(", using indicator values: "); text.append(((MakeIndicator)m_ClassFilters[i]).getValueRange()); } } text.append('\n'); text.append(m_Classifiers[i].toString() + "\n\n"); } else { text.append(" Skipped (no training examples)\n"); } } return text.toString(); }
/** * Set the value of ResultsetKeyColumns. * * @param newResultsetKeyColumns Value to assign to ResultsetKeyColumns. */ @Override public void setResultsetKeyColumns(Range newResultsetKeyColumns) { m_ResultsetKeyColumnsRange = newResultsetKeyColumns; m_ResultsetsValid = false; }
/** * Set the value of DatasetKeyColumns. * * @param newDatasetKeyColumns Value to assign to DatasetKeyColumns. */ @Override public void setDatasetKeyColumns(Range newDatasetKeyColumns) { m_DatasetKeyColumnsRange = newDatasetKeyColumns; m_ResultsetsValid = false; }
public void setResultKeyFromDialog() { ListSelectorDialog jd = new ListSelectorDialog(null, m_ResultKeyList); // Open the dialog int result = jd.showDialog(); // If accepted, update the ttester if (result == ListSelectorDialog.APPROVE_OPTION) { int[] selected = m_ResultKeyList.getSelectedIndices(); String selectedList = ""; for (int element : selected) { selectedList += "," + (element + 1); } Range generatorRange = new Range(); if (selectedList.length() != 0) { try { generatorRange.setRanges(selectedList); } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); } } m_TTester.setResultsetKeyColumns(generatorRange); setTTester(); } }
public void setDatasetKeyFromDialog() { ListSelectorDialog jd = new ListSelectorDialog(null, m_DatasetKeyList); // Open the dialog int result = jd.showDialog(); // If accepted, update the ttester if (result == ListSelectorDialog.APPROVE_OPTION) { int[] selected = m_DatasetKeyList.getSelectedIndices(); String selectedList = ""; for (int element : selected) { selectedList += "," + (element + 1); } Range generatorRange = new Range(); if (selectedList.length() != 0) { try { generatorRange.setRanges(selectedList); } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); } } m_TTester.setDatasetKeyColumns(generatorRange); setTTester(); } }
/** * tests the data whether the filter can actually handle it. * * @param instanceInfo the data to test * @throws Exception if the test fails */ @Override protected void testInputFormat(Instances instanceInfo) throws Exception { for (int i = 0; i < getRanges().length; i++) { Instances newi = new Instances(instanceInfo, 0); if (instanceInfo.size() > 0) { newi.add((Instance) instanceInfo.get(0).copy()); } Range range = getRanges()[i]; range.setUpper(instanceInfo.numAttributes() - 1); Instances subset = generateSubset(newi, range); getFilters()[i].setInputFormat(subset); } }
/** * generates a subset of the dataset with only the attributes from the range * (class is always added if present). * * @param data the data to work on * @param range the range of attribute to use * @return the generated subset * @throws Exception if creation fails */ protected Instances generateSubset(Instances data, Range range) throws Exception { Remove filter; StringBuilder atts; Instances result; int[] indices; int i; // determine attributes indices = range.getSelection(); atts = new StringBuilder(); for (i = 0; i < indices.length; i++) { if (i > 0) { atts.append(","); } atts.append("" + (indices[i] + 1)); } if ((data.classIndex() > -1) && (!range.isInRange(data.classIndex()))) { atts.append("," + (data.classIndex() + 1)); } // setup filter filter = new Remove(); filter.setAttributeIndices(atts.toString()); filter.setInvertSelection(true); filter.setInputFormat(data); // generate output result = Filter.useFilter(data, filter); return result; }
/** * Constructor */ public GreedyStepwise () { m_threshold = -Double.MAX_VALUE; m_doneRanking = false; m_startRange = new Range(); m_starting = null; resetOptions(); }
/** * Resets stuff to default values */ protected void resetOptions () { m_starting = null; m_startRange = new Range(); m_attributeList = null; m_attributeMerit = null; m_threshold = -Double.MAX_VALUE; }
/** * Reset options to default values */ protected void resetOptions () { m_maxStale = 5; m_searchDirection = SELECTION_FORWARD; m_starting = null; m_startRange = new Range(); m_classIndex = -1; m_totalEvals = 0; m_cacheSize = 1; m_debug = false; }
public void setResultKeyFromDialog() { ListSelectorDialog jd = new ListSelectorDialog(null, m_ResultKeyList); // Open the dialog int result = jd.showDialog(); // If accepted, update the ttester if (result == ListSelectorDialog.APPROVE_OPTION) { int [] selected = m_ResultKeyList.getSelectedIndices(); String selectedList = ""; for (int i = 0; i < selected.length; i++) { selectedList += "," + (selected[i] + 1); } Range generatorRange = new Range(); if (selectedList.length() != 0) { try { generatorRange.setRanges(selectedList); } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); } } m_TTester.setResultsetKeyColumns(generatorRange); setTTester(); } }
public void setDatasetKeyFromDialog() { ListSelectorDialog jd = new ListSelectorDialog(null, m_DatasetKeyList); // Open the dialog int result = jd.showDialog(); // If accepted, update the ttester if (result == ListSelectorDialog.APPROVE_OPTION) { int [] selected = m_DatasetKeyList.getSelectedIndices(); String selectedList = ""; for (int i = 0; i < selected.length; i++) { selectedList += "," + (selected[i] + 1); } Range generatorRange = new Range(); if (selectedList.length() != 0) { try { generatorRange.setRanges(selectedList); } catch (Exception ex) { ex.printStackTrace(); System.err.println(ex.getMessage()); } } m_TTester.setDatasetKeyColumns(generatorRange); setTTester(); } }
/** * tests the data whether the filter can actually handle it. * * @param instanceInfo the data to test * @throws Exception if the test fails */ protected void testInputFormat(Instances instanceInfo) throws Exception { for (int i = 0; i < getRanges().length; i++) { Instances newi = new Instances(instanceInfo, 0); if (instanceInfo.size() > 0){ newi.add((Instance)instanceInfo.get(0).copy()); } Range range = getRanges()[i]; range.setUpper(instanceInfo.numAttributes() - 1); Instances subset = generateSubset(newi, range); getFilters()[i].setInputFormat(subset); } }
/** * generates a subset of the dataset with only the attributes from the range * (class is always added if present). * * @param data the data to work on * @param range the range of attribute to use * @return the generated subset * @throws Exception if creation fails */ protected Instances generateSubset(Instances data, Range range) throws Exception { Remove filter; StringBuilder atts; Instances result; int[] indices; int i; // determine attributes indices = range.getSelection(); atts = new StringBuilder(); for (i = 0; i < indices.length; i++) { if (i > 0) atts.append(","); atts.append("" + (indices[i] + 1)); } if ((data.classIndex() > -1) && (!range.isInRange(data.classIndex()))) atts.append("," + (data.classIndex() + 1)); // setup filter filter = new Remove(); filter.setAttributeIndices(atts.toString()); filter.setInvertSelection(true); filter.setInputFormat(data); // generate output result = Filter.useFilter(data, filter); return result; }