/** * 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 RemoveFolds(), argv); } }
/** * Input an instance for filtering. Filter requires all training instances be * read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws IllegalStateException if no input structure 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; } if (isFirstBatchDone()) { push(instance); return true; } else { bufferInput(instance); return false; } }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); options.add("-S"); options.add("" + getSeed()); if (getInvertSelection()) { options.add("-V"); } options.add("-N"); options.add("" + getNumFolds()); options.add("-F"); options.add("" + getFold()); return options.toArray(new String[0]); }
public void setOptions(String[] options) throws Exception { setInvertSelection(Utils.getFlag('V', options)); String numFolds = Utils.getOption('N', options); if (numFolds.length() != 0) { setNumFolds(Integer.parseInt(numFolds)); } else { setNumFolds(10); setFold(Integer.parseInt(fold)); } else { setFold(1); setSeed(Integer.parseInt(seed)); } else { setSeed(0); if (getInputFormat() != null) { setInputFormat(getInputFormat());
public boolean batchFinished() { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); if (!isFirstBatchDone()) { if (m_Seed > 0) { getInputFormat().randomize(new Random(m_Seed)); instances = getInputFormat().testCV(m_NumFolds, m_Fold - 1); } else { instances = getInputFormat().trainCV(m_NumFolds, m_Fold - 1); instances = getInputFormat(); flushInput(); push(instances.instance(i), false); // No need to copy instance because of bufferInput() return (numPendingOutput() != 0);
public void testAllFolds() { int totInstances = 0; for (int i = 0; i < 10; i++) { ((RemoveFolds)m_Filter).setFold(i + 1); Instances result = useFilter(); assertEquals(m_Instances.numAttributes(), result.numAttributes()); totInstances += result.numInstances(); } assertEquals("Expecting output number of instances to match", m_Instances.numInstances(), totInstances); }
/** Creates a default RemoveFolds */ public Filter getFilter() { RemoveFolds f = new RemoveFolds(); return f; }
public void setOptions(String[] options) throws Exception { setInvertSelection(Utils.getFlag('V', options)); String numFolds = Utils.getOption('N', options); if (numFolds.length() != 0) { setNumFolds(Integer.parseInt(numFolds)); } else { setNumFolds(10); setFold(Integer.parseInt(fold)); } else { setFold(1); setSeed(Integer.parseInt(seed)); } else { setSeed(0); if (getInputFormat() != null) { setInputFormat(getInputFormat());
public boolean batchFinished() { if (getInputFormat() == null) { throw new IllegalStateException("No input instance format defined"); if (!isFirstBatchDone()) { if (m_Seed > 0) { getInputFormat().randomize(new Random(m_Seed)); instances = getInputFormat().testCV(m_NumFolds, m_Fold - 1); } else { instances = getInputFormat().trainCV(m_NumFolds, m_Fold - 1); instances = getInputFormat(); flushInput(); push(instances.instance(i), false); // No need to copy instance because of bufferInput() return (numPendingOutput() != 0);
public void testAllFolds() { int totInstances = 0; for (int i = 0; i < 10; i++) { ((RemoveFolds)m_Filter).setFold(i + 1); Instances result = useFilter(); assertEquals(m_Instances.numAttributes(), result.numAttributes()); totInstances += result.numInstances(); } assertEquals("Expecting output number of instances to match", m_Instances.numInstances(), totInstances); }
/** Creates a default RemoveFolds */ public Filter getFilter() { RemoveFolds f = new RemoveFolds(); return f; }
/** * Input an instance for filtering. Filter requires all training instances be * read before producing output. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws IllegalStateException if no input structure 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; } if (isFirstBatchDone()) { push(instance); return true; } else { bufferInput(instance); return false; } }
/** * Gets the current settings of the filter. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); options.add("-S"); options.add("" + getSeed()); if (getInvertSelection()) { options.add("-V"); } options.add("-N"); options.add("" + getNumFolds()); options.add("-F"); options.add("" + getFold()); return options.toArray(new String[0]); }
/** * 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 RemoveFolds(), argv); } }