/** * Main method for testing this class. * * @param argv should contain arguments to the filter: use -h for help */ public static void main(String[] argv) { runFilter(new NumericToBinary(), argv); } }
public void setOptions(String[] options) throws Exception { setInvertSelection(Utils.getFlag('V', options)); setAttributeIndices(tmpStr); } else { setAttributeIndices(m_DefaultCols); if (getInputFormat() != null) { setInputFormat(getInputFormat());
/** * Input an instance for filtering. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws IllegalStateException if no input format has been defined. */ @Override public boolean input(Instance instance) { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } convertInstance(instance); return true; }
@Override public String[] getOptions() { Vector<String> result = new Vector<String>(); if ( !getAttributeIndices().equals("") ) { result.add("-R"); result.add(getAttributeIndices()); } if( getInvertSelection() ) { result.add("-V"); } return result.toArray( new String[result.size()] ); }
/** * Make sure the filter binarizes the index we specify + invert */ public void testInvertSelection() { int att1 = m_Instances.attribute("NumericAtt1").index(); int att2 = m_Instances.attribute("NumericAtt2").index(); // Set the attribute index to point to NumericAtt1, but invert the selection, so that // it will try to apply the filter to *every other* attribute. Of course, because this // only applies to numeric attributes, the filter should only change NumericAtt2 ((NumericToBinary)m_Filter).setAttributeIndices( String.valueOf(att2+1) ); ((NumericToBinary)m_Filter).setInvertSelection(true); Instances result = useFilter(); assertTrue("NumericAtt1 should be nominal", result.attribute(att1).isNominal()); assertTrue("NumericAtt2 should be numeric", result.attribute(att2).isNumeric()); }
data = Filter.useFilter(data, disTransform); } else { NumericToBinary binTransform = new NumericToBinary(); binTransform.setInputFormat(data); data = Filter.useFilter(data, binTransform);
for (int j = 0; j < instance.numValues(); j++) { Attribute att = getInputFormat().attribute(instance.index(j)); if ((!att.isNumeric()) || (instance.index(j) == getInputFormat().classIndex()) || !m_Cols.isInRange(instance.index(j))) { vals[j] = instance.valueSparse(j); outputFormatPeek().numAttributes()); } else { double[] vals = new double[outputFormatPeek().numAttributes()]; for (int j = 0; j < getInputFormat().numAttributes(); j++) { Attribute att = getInputFormat().attribute(j); if ((!att.isNumeric()) || (j == getInputFormat().classIndex()) || !m_Cols.isInRange(j)) { vals[j] = instance.value(j); push(inst, false); // No need to copy
/** * Sets which attributes are to be transformed to binary. (only numeric * attributes among the selection will be transformed). * * @param value an array containing indexes of attributes to binarize. Since * the array will typically come from a program, attributes are * indexed from 0. * @throws IllegalArgumentException if an invalid set of ranges is supplied */ public void setAttributeIndicesArray(int[] value) { setAttributeIndices(Range.indicesToRangeList(value)); }
/** Creates an example NumericToBinary */ public Filter getFilter() { NumericToBinary f = new NumericToBinary(); return f; }
ArrayList<String> vals; m_Cols.setUpper(getInputFormat().numAttributes() - 1); newClassIndex = getInputFormat().classIndex(); newAtts = new ArrayList<Attribute>(); for (int j = 0; j < getInputFormat().numAttributes(); j++) { Attribute att = getInputFormat().attribute(j); if ((j == newClassIndex) || (!att.isNumeric()) || !m_Cols.isInRange(j) ) { outputFormat = new Instances(getInputFormat().relationName(), newAtts, 0); outputFormat.setClassIndex(newClassIndex); setOutputFormat(outputFormat);
/** * Make sure the filter binarizes the index we specify + invert */ public void testInvertSelection() { int att1 = m_Instances.attribute("NumericAtt1").index(); int att2 = m_Instances.attribute("NumericAtt2").index(); // Set the attribute index to point to NumericAtt1, but invert the selection, so that // it will try to apply the filter to *every other* attribute. Of course, because this // only applies to numeric attributes, the filter should only change NumericAtt2 ((NumericToBinary)m_Filter).setAttributeIndices( String.valueOf(att2+1) ); ((NumericToBinary)m_Filter).setInvertSelection(true); Instances result = useFilter(); assertTrue("NumericAtt1 should be nominal", result.attribute(att1).isNominal()); assertTrue("NumericAtt2 should be numeric", result.attribute(att2).isNumeric()); }
data = Filter.useFilter(data, disTransform); } else { NumericToBinary binTransform = new NumericToBinary(); binTransform.setInputFormat(data); data = Filter.useFilter(data, binTransform);
for (int j = 0; j < instance.numValues(); j++) { Attribute att = getInputFormat().attribute(instance.index(j)); if ((!att.isNumeric()) || (instance.index(j) == getInputFormat().classIndex()) || !m_Cols.isInRange(instance.index(j))) { vals[j] = instance.valueSparse(j); outputFormatPeek().numAttributes()); } else { double[] vals = new double[outputFormatPeek().numAttributes()]; for (int j = 0; j < getInputFormat().numAttributes(); j++) { Attribute att = getInputFormat().attribute(j); if ((!att.isNumeric()) || (j == getInputFormat().classIndex()) || !m_Cols.isInRange(j)) { vals[j] = instance.value(j); push(inst, false); // No need to copy
/** * Sets which attributes are to be transformed to binary. (only numeric * attributes among the selection will be transformed). * * @param value an array containing indexes of attributes to binarize. Since * the array will typically come from a program, attributes are * indexed from 0. * @throws IllegalArgumentException if an invalid set of ranges is supplied */ public void setAttributeIndicesArray(int[] value) { setAttributeIndices(Range.indicesToRangeList(value)); }
/** Creates an example NumericToBinary */ public Filter getFilter() { NumericToBinary f = new NumericToBinary(); return f; }
@Override public String[] getOptions() { Vector<String> result = new Vector<String>(); if ( !getAttributeIndices().equals("") ) { result.add("-R"); result.add(getAttributeIndices()); } if( getInvertSelection() ) { result.add("-V"); } return result.toArray( new String[result.size()] ); }
ArrayList<String> vals; m_Cols.setUpper(getInputFormat().numAttributes() - 1); newClassIndex = getInputFormat().classIndex(); newAtts = new ArrayList<Attribute>(); for (int j = 0; j < getInputFormat().numAttributes(); j++) { Attribute att = getInputFormat().attribute(j); if ((j == newClassIndex) || (!att.isNumeric()) || !m_Cols.isInRange(j) ) { outputFormat = new Instances(getInputFormat().relationName(), newAtts, 0); outputFormat.setClassIndex(newClassIndex); setOutputFormat(outputFormat);
public void setOptions(String[] options) throws Exception { setInvertSelection(Utils.getFlag('V', options)); setAttributeIndices(tmpStr); } else { setAttributeIndices(m_DefaultCols); if (getInputFormat() != null) { setInputFormat(getInputFormat());
/** * Make sure the filter binarizes the appropriate attributes in the range * we specify */ public void testRange() { int att1 = m_Instances.attribute("NumericAtt1").index(); int att2 = m_Instances.attribute("NumericAtt2").index(); // Use the string expression "first-last" for the attribute index. This should // change both numeric attributes. ((NumericToBinary)m_Filter).setAttributeIndices("first-last"); ((NumericToBinary)m_Filter).setInvertSelection(false); Instances result = useFilter(); assertTrue("NumericAtt1 should be nominal", result.attribute(att1).isNominal()); assertTrue("NumericAtt2 should be nominal", result.attribute(att2).isNominal()); }
data = Filter.useFilter(data, disTransform); } else { NumericToBinary binTransform = new NumericToBinary(); binTransform.setInputFormat(data); data = Filter.useFilter(data, binTransform);