org.knime.base.node.preproc.sample
Class RandomFractionRowFilter

java.lang.Object
  extended by org.knime.base.node.preproc.filter.row.rowfilter.RowFilter
      extended by org.knime.base.node.preproc.sample.RandomFractionRowFilter
All Implemented Interfaces:
Cloneable

public class RandomFractionRowFilter
extends RowFilter

Row Filter class that extracts randomly a given fraction of rows. The implementation of the matches(DataRow, int) method only tests if a random number is less or equal to the fraction argument and if so it will return true, i.e. will accept the row currently requested.

The implementation ensures that cloned objects from this object have the same behaviour (presuming that the matches(DataRow, int) method is called in the same sequence)

Author:
Bernd Wiswedel, University of Konstanz

Constructor Summary
RandomFractionRowFilter(double fraction)
          Creates new Filter that filters out (1-fraction) * 100 percent of the rows.
 
Method Summary
 Object clone()
          
 DataTableSpec configure(DataTableSpec inSpec)
          Throws exception, not supported.
 void loadSettingsFrom(NodeSettingsRO cfg)
          Throws exception, not supported.
 boolean matches(DataRow row, int rowIndex)
          Return true if the specified row matches the criteria set in the filter.
protected  void saveSettings(NodeSettingsWO cfg)
          Throws exception, not supported.
 
Methods inherited from class org.knime.base.node.preproc.filter.row.rowfilter.RowFilter
saveSettingsTo
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RandomFractionRowFilter

public RandomFractionRowFilter(double fraction)
Creates new Filter that filters out (1-fraction) * 100 percent of the rows.

Parameters:
fraction - the fraction of the rows to surive
Method Detail

matches

public boolean matches(DataRow row,
                       int rowIndex)
                throws EndOfTableException,
                       IncludeFromNowOn
Return true if the specified row matches the criteria set in the filter. Can throw a EndOfTableException if the filter can tell that no more rows of the table will be able to fulfill the criteria.

Specified by:
matches in class RowFilter
Parameters:
row - the row to test
rowIndex - the row index of the passed row in the original table
Returns:
true if the row matches the criteria set in the filter, false if not
Throws:
EndOfTableException - if there is no chance that any of the rows coming (including the current rowIndex) will fulfill the criteria, thus no further row in the original table will be a match to this filter. (In general this is hard to tell, but a row number filter can certainly use it.) If the exception is received the row filter table iterator will flag an end of table.
IncludeFromNowOn - if the current and all following rows from now on are to be included into the result table

loadSettingsFrom

public void loadSettingsFrom(NodeSettingsRO cfg)
                      throws InvalidSettingsException
Throws exception, not supported.

Specified by:
loadSettingsFrom in class RowFilter
Parameters:
cfg - the object holding the settings to load
Throws:
InvalidSettingsException - if cfg contains invalid/incorrect/inconsistent settings
See Also:
RowFilter.loadSettingsFrom(NodeSettingsRO)

saveSettings

protected void saveSettings(NodeSettingsWO cfg)
Throws exception, not supported.

Specified by:
saveSettings in class RowFilter
Parameters:
cfg - object to add the current internal settings to
See Also:
RowFilter.saveSettings(NodeSettingsWO)

configure

public DataTableSpec configure(DataTableSpec inSpec)
                        throws InvalidSettingsException
Throws exception, not supported.

Specified by:
configure in class RowFilter
Parameters:
inSpec - the new spec propagated into the row filter node. Could be null or empty!
Returns:
a new table spec, if you can
Throws:
InvalidSettingsException - if the settings in the row filter are not compatible with the table spec coming in
See Also:
RowFilter.configure(org.knime.core.data.DataTableSpec)

clone

public Object clone()

Overrides:
clone in class RowFilter


Copyright, 2003 - 2010. All rights reserved.
University of Konstanz, Germany.
Chair for Bioinformatics and Information Mining, Prof. Dr. Michael R. Berthold.
You may not modify, publish, transmit, transfer or sell, reproduce, create derivative works from, distribute, perform, display, or in any way exploit any of the content, in whole or in part, except as otherwise expressly permitted in writing by the copyright owner or as specified in the license file distributed with this product.