/** * Signify that this batch of input to the filter is finished. If the filter * requires all instances prior to filtering, output() may now be called to * retrieve the filtered instances. * * @return true if there are instances pending output * @throws Exception if no input structure has been defined */ @Override public boolean batchFinished() throws Exception { if (getInputFormat() == null) { throw new Exception("No input instance format defined"); } // Do the subsample, and clear the input instances. addNoise(getInputFormat(), m_RandomSeed, m_Percent, m_AttIndex.getIndex(), m_UseMissing); for (int i = 0; i < getInputFormat().numInstances(); i++) { push((Instance) getInputFormat().instance(i).copy(), false); // No need to copy instance } flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
/** * Input an instance for filtering. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws Exception if the input format was not set */ @Override public boolean input(Instance instance) throws Exception { // check if input format is defined if (getInputFormat() == null) { throw new Exception("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("-C"); options.add("" + getAttributeIndex()); if (getUseMissing()) { options.add("-M"); } options.add("-P"); options.add("" + getPercent()); options.add("-S"); options.add("" + getRandomSeed()); return options.toArray(new String[0]); }
setAttributeIndex(indexString); } else { setAttributeIndex("last"); setUseMissing(true); setPercent((int) Double.valueOf(percentString).doubleValue()); } else { setPercent(10); setRandomSeed(Integer.parseInt(seedString)); } else { setRandomSeed(1);
/** Creates a default AddNoise */ public Filter getFilter() { AddNoise f = new AddNoise(); return f; }
public void testNoNoise() { m_Filter = getFilter(); ((AddNoise) m_Filter).setPercent(0); Instances result = useFilter(); assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(m_Instances.numInstances(), result.numInstances()); // all instance's must be the same boolean equal = true; for (int i = 0; i < m_Instances.numInstances(); i++) { if (m_Comparator.compare( m_Instances.instance(i), result.instance(i)) != 0) { equal = false; break; } } if (!equal) fail("Instances modified!"); }
m_AttIndex.setUpper(getInputFormat().numAttributes() - 1); if (!getInputFormat().attribute(m_AttIndex.getIndex()).isNominal()) { throw new Exception("Adding noise is not possible:" + "Chosen attribute is numeric."); if ((getInputFormat().attribute(m_AttIndex.getIndex()).numValues() < 2) && (!m_UseMissing)) { throw new Exception("Adding noise is not possible:" setOutputFormat(getInputFormat()); m_NewBatch = true; return false;
@ProgrammaticProperty public int getSeed() { return getRandomSeed(); }
changeValueRandomly(randomValue, numOfValues, attIndex, currInstance, useMissing); missing_count++; int vIndex = (int) currInstance.value(attIndex); if (partition_count[vIndex] < partition_max[vIndex]) { changeValueRandomly(randomValue, numOfValues, attIndex, currInstance, useMissing); partition_count[vIndex]++;
setAttributeIndex(indexString); } else { setAttributeIndex("last"); setUseMissing(true); setPercent((int) Double.valueOf(percentString).doubleValue()); } else { setPercent(10); setRandomSeed(Integer.parseInt(seedString)); } else { setRandomSeed(1);
/** * 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("-C"); options.add("" + getAttributeIndex()); if (getUseMissing()) { options.add("-M"); } options.add("-P"); options.add("" + getPercent()); options.add("-S"); options.add("" + getRandomSeed()); return options.toArray(new String[0]); }
/** Creates a default AddNoise */ public Filter getFilter() { AddNoise f = new AddNoise(); return f; }
public void testNoNoise() { m_Filter = getFilter(); ((AddNoise) m_Filter).setPercent(0); Instances result = useFilter(); assertEquals(m_Instances.numAttributes(), result.numAttributes()); assertEquals(m_Instances.numInstances(), result.numInstances()); // all instance's must be the same boolean equal = true; for (int i = 0; i < m_Instances.numInstances(); i++) { if (m_Comparator.compare( m_Instances.instance(i), result.instance(i)) != 0) { equal = false; break; } } if (!equal) fail("Instances modified!"); }
m_AttIndex.setUpper(getInputFormat().numAttributes() - 1); if (!getInputFormat().attribute(m_AttIndex.getIndex()).isNominal()) { throw new Exception("Adding noise is not possible:" + "Chosen attribute is numeric."); if ((getInputFormat().attribute(m_AttIndex.getIndex()).numValues() < 2) && (!m_UseMissing)) { throw new Exception("Adding noise is not possible:" setOutputFormat(getInputFormat()); m_NewBatch = true; return false;
@ProgrammaticProperty public int getSeed() { return getRandomSeed(); }
changeValueRandomly(randomValue, numOfValues, attIndex, currInstance, useMissing); missing_count++; int vIndex = (int) currInstance.value(attIndex); if (partition_count[vIndex] < partition_max[vIndex]) { changeValueRandomly(randomValue, numOfValues, attIndex, currInstance, useMissing); partition_count[vIndex]++;
/** * Signify that this batch of input to the filter is finished. If the filter * requires all instances prior to filtering, output() may now be called to * retrieve the filtered instances. * * @return true if there are instances pending output * @throws Exception if no input structure has been defined */ @Override public boolean batchFinished() throws Exception { if (getInputFormat() == null) { throw new Exception("No input instance format defined"); } // Do the subsample, and clear the input instances. addNoise(getInputFormat(), m_RandomSeed, m_Percent, m_AttIndex.getIndex(), m_UseMissing); for (int i = 0; i < getInputFormat().numInstances(); i++) { push((Instance) getInputFormat().instance(i).copy(), false); // No need to copy instance } flushInput(); m_NewBatch = true; m_FirstBatchDone = true; return (numPendingOutput() != 0); }
/** * Input an instance for filtering. * * @param instance the input instance * @return true if the filtered instance may now be collected with output(). * @throws Exception if the input format was not set */ @Override public boolean input(Instance instance) throws Exception { // check if input format is defined if (getInputFormat() == null) { throw new Exception("No input instance format defined"); } if (m_NewBatch) { resetQueue(); m_NewBatch = false; } if (isFirstBatchDone()) { push(instance); return true; } else { bufferInput(instance); return false; } }