Package ubic.basecode.math
Class MatrixStats
java.lang.Object
ubic.basecode.math.MatrixStats
- Author:
- pavlidis
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <R,C> DoubleMatrix1D colSums(DoubleMatrix<R, C> data) NaN values are omitted from calculations.static <R,C> void convertToLog2(DoubleMatrix<R, C> matrix, double base) Convert a log_b-transformed data set to log 2.static <R,C> DoubleMatrix <R, C> convertToLog2Cpm(DoubleMatrix<R, C> matrix, DoubleMatrix1D librarySize) Convert a count matrix to log2 counts per million.static <R,C> DoubleMatrix <R, R> correlationMatrix(DoubleMatrix<R, C> data) Compute the correlation matrix of the rows of a matrix.static <R,C> SparseDoubleMatrix <R, R> correlationMatrix(DoubleMatrix<R, C> data, double threshold) static DoubleMatrix2Dcov2cor(DoubleMatrix2D cov) Scale a covariance matrix to the corresponding correlation matrix.static <R,C> DoubleMatrix <R, C> doubleStandardize(DoubleMatrix<R, C> matrix) Iteratively standardize the columns and rows of the matrix.static <R,C> void logTransform(DoubleMatrix<R, C> matrix) Log-transform the values in a matrix (log base 2).static <R,C> double max(DoubleMatrix<R, C> matrix) Compute the maximum value in the matrix.static <R,C> double min(DoubleMatrix<R, C> matrix) Find the minimum of the entire matrix.static boolean[][]nanStatusMatrix(double[][] data) static <R,C> void rbfNormalize(DoubleMatrix<R, C> matrixToNormalize, double sigma) Normalize a matrix in place to be a transition matrix.static double[][]selfSquaredMatrix(double[][] input) static <R,C> DoubleMatrix <R, C> standardize(DoubleMatrix<R, C> matrix) Scale the rows of the matrix; returns a new matrix.static <R,C> void unLogTransform(DoubleMatrix<R, C> matrix) Undo log2 transform.
-
Constructor Details
-
MatrixStats
public MatrixStats()
-
-
Method Details
-
colSums
NaN values are omitted from calculations.- Type Parameters:
R-C-- Parameters:
data-- Returns:
- column sums
-
convertToLog2
Convert a log_b-transformed data set to log 2.- Parameters:
matrix-base- the current base
-
convertToLog2Cpm
public static <R,C> DoubleMatrix<R,C> convertToLog2Cpm(DoubleMatrix<R, C> matrix, DoubleMatrix1D librarySize) Convert a count matrix to log2 counts per million. Equivalent tot(log2(t(counts+0.5)/(lib.size+1)*1e6))in R. (NOTE: originally this did the operation in place)- Parameters:
matrix-librarySize- if null, it will default tocolSums(matrix).- Returns:
-
correlationMatrix
Compute the correlation matrix of the rows of a matrix.- Parameters:
data-- Returns:
- a symmetric matrix that has the rows and columns set to be the names of the rows of the input.
-
correlationMatrix
public static <R,C> SparseDoubleMatrix<R,R> correlationMatrix(DoubleMatrix<R, C> data, double threshold) - Parameters:
data- DenseDoubleMatrix2DNamedthreshold- only correlations with absolute values above this level are stored (others are Double.NaN)- Returns:
- a sparse symmetric matrix that has the rows and columns set to be the names of the rows of the input. The diagonal is set to Double.NaN
-
doubleStandardize
Iteratively standardize the columns and rows of the matrix.- Parameters:
data-
-
logTransform
Log-transform the values in a matrix (log base 2). Values that are less than or equal to zero are left as Double.NaN.- Parameters:
matrixToNormalize-
-
max
Compute the maximum value in the matrix.- Parameters:
matrix- DenseDoubleMatrix2DNamed- Returns:
- the largest value in the matrix
-
min
Find the minimum of the entire matrix.- Parameters:
matrix- DenseDoubleMatrix2DNamed- Returns:
- the smallest value in the matrix
-
nanStatusMatrix
public static boolean[][] nanStatusMatrix(double[][] data) - Parameters:
data-- Returns:
- matrix indicating whether each value in the input matix is NaN.
-
rbfNormalize
Normalize a matrix in place to be a transition matrix. Assumes that values operate such that small values like p values represent closer distances, and the values are probabilities.Each point is first transformed via v' = exp(-v/sigma). Then the values for each node's edges are adjusted to sum to 1.
- Parameters:
matrixToNormalize-sigma- a scaling factor for the input values.
-
selfSquaredMatrix
public static double[][] selfSquaredMatrix(double[][] input) - Parameters:
input- raw double 2-d matrix- Returns:
- the element-by-element product (not matrix product) of the matrix.
-
standardize
Scale the rows of the matrix; returns a new matrix.- Type Parameters:
R-C-- Parameters:
data-- Returns:
-
cov2cor
Scale a covariance matrix to the corresponding correlation matrix.- Parameters:
cov- a symmetric matrix of covariances- Returns:
-
unLogTransform
Undo log2 transform.- Type Parameters:
R-C-- Parameters:
matrix-
-