List of usage examples for org.apache.commons.math3.linear RealMatrix copy
RealMatrix copy();
From source file:org.rhwlab.dispim.nucleus.Nucleus.java
private RealMatrix reverseHandedness(RealMatrix m) { RealMatrix ret = m.copy(); for (int c = 0; c < m.getColumnDimension(); ++c) { ret.setEntry(0, c, -m.getEntry(0, c)); }/*from w w w .j av a 2 s. co m*/ return ret; }
From source file:stats.SpearmansCorrelation.java
/** * Applies rank transform to each of the columns of <code>matrix</code> using * the current <code>rankingAlgorithm</code>. * * @param matrix/*from w w w . j a va 2s.c om*/ * 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; }