View Javadoc

    1   package baseCode.dataFilter;
    2
    3   import baseCode.dataStructure.matrix.DenseDoubleMatrix2DNamed;
    4   import baseCode.dataStructure.matrix.NamedMatrix;
    5
    6   /***
    7    * Filter that remove individual values that are outside of a range. Removed values are set to NaN.
    8    * <p>
    9    * Copyright (c) 2004 Columbia University
    10   *
    11   * @author Pavlidis
    12   * @version $Id: ItemLevelFilter.java,v 1.5 2004/07/27 03:18:58 pavlidis Exp $
    13   */
    14  public class ItemLevelFilter extends AbstractLevelFilter {
    15
    16     public NamedMatrix filter( NamedMatrix data ) {
    17        if ( !( data instanceof DenseDoubleMatrix2DNamed ) ) {
    18           throw new IllegalArgumentException(
    19                 "Only valid for DenseDoubleMatrix2DNamed" );
    20        }
    21
    22        if ( lowCut == -Double.MAX_VALUE && highCut == Double.MAX_VALUE ) {
    23           log.info( "No filtering requested" );
    24           return data;
    25        }
    26
    27        int numRows = data.rows();
    28        int numCols = data.columns();
    29        DenseDoubleMatrix2DNamed returnval = new DenseDoubleMatrix2DNamed(
    30              numRows, numCols );
    31        for ( int i = 0; i < numRows; i++ ) {
    32
    33           for ( int j = 0; j < numCols; j++ ) {
    34
    35              double newVal = ( ( DenseDoubleMatrix2DNamed ) data ).get( i, j );
    36              if ( newVal < lowCut || newVal > highCut ) {
    37                 newVal = Double.NaN;
    38              }
    39
    40              returnval.set( i, j, newVal );
    41           }
    42        }
    43        returnval.setColumnNames( data.getColNames() );
    44        returnval.setRowNames( data.getRowNames() );
    45
    46        return returnval;
    47     }
    48
    49  }