Пример #1
0
  /**
   * Applies rank transform to each of the columns of <code>matrix</code> using the current <code>
   * rankingAlgorithm</code>
   *
   * @param matrix matrix to transform
   * @return a rank-transformed matrix
   */
  private RealMatrix rankTransform(final RealMatrix matrix) {
    RealMatrix transformed = null;

    if (rankingAlgorithm instanceof NaturalRanking
        && ((NaturalRanking) rankingAlgorithm).getNanStrategy() == NaNStrategy.REMOVED) {
      final Set<Integer> nanPositions = new HashSet<Integer>();
      for (int i = 0; i < matrix.getColumnDimension(); i++) {
        nanPositions.addAll(getNaNPositions(matrix.getColumn(i)));
      }

      // if we have found NaN values, we have to update the matrix size
      if (!nanPositions.isEmpty()) {
        transformed =
            new BlockRealMatrix(
                matrix.getRowDimension() - nanPositions.size(), matrix.getColumnDimension());
        for (int i = 0; i < transformed.getColumnDimension(); i++) {
          transformed.setColumn(i, removeValues(matrix.getColumn(i), nanPositions));
        }
      }
    }

    if (transformed == null) {
      transformed = matrix.copy();
    }

    for (int i = 0; i < transformed.getColumnDimension(); i++) {
      transformed.setColumn(i, rankingAlgorithm.rank(transformed.getColumn(i)));
    }

    return transformed;
  }
Пример #2
0
 /**
  * Returns a list containing the indices of NaN values in the input array.
  *
  * @param input the input array
  * @return a list of NaN positions in the input array
  */
 private void rankTransform(RealMatrix matrix) {
   for (int i = 0; i < matrix.getColumnDimension(); i++) {
     matrix.setColumn(i, rankingAlgorithm.rank(matrix.getColumn(i)));
   }
 }