*
* @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;
}