Class MatrixStats


  • public class MatrixStats
    extends Object
    Author:
    pavlidis
    • Constructor Detail

      • MatrixStats

        public MatrixStats()
    • Method Detail

      • colSums

        public static <R,​C> cern.colt.matrix.DoubleMatrix1D colSums​(DoubleMatrix<R,​C> data)
        NaN values are omitted from calculations.
        Type Parameters:
        R -
        C -
        Parameters:
        data -
        Returns:
        column sums
      • convertToLog2

        public static <R,​C> void convertToLog2​(DoubleMatrix<R,​C> matrix,
                                                     double base)
        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,
                                                                           cern.colt.matrix.DoubleMatrix1D librarySize)
        Convert a count matrix to log2 counts per million. Equivalent to t(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 to colSums(matrix).
        Returns:
      • correlationMatrix

        public static <R,​C> DoubleMatrix<R,​R> correlationMatrix​(DoubleMatrix<R,​C> data)
        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 - DenseDoubleMatrix2DNamed
        threshold - 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

        public static <R,​C> DoubleMatrix<R,​C> doubleStandardize​(DoubleMatrix<R,​C> matrix)
        Iteratively standardize the columns and rows of the matrix.
        Parameters:
        data -
      • logTransform

        public static <R,​C> void logTransform​(DoubleMatrix<R,​C> matrix)
        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

        public static <R,​C> double max​(DoubleMatrix<R,​C> matrix)
        Compute the maximum value in the matrix.
        Parameters:
        matrix - DenseDoubleMatrix2DNamed
        Returns:
        the largest value in the matrix
      • min

        public static <R,​C> double min​(DoubleMatrix<R,​C> matrix)
        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

        public static <R,​C> void rbfNormalize​(DoubleMatrix<R,​C> matrixToNormalize,
                                                    double sigma)
        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

        public static <R,​C> DoubleMatrix<R,​C> standardize​(DoubleMatrix<R,​C> matrix)
        Scale the rows of the matrix; returns a new matrix.
        Type Parameters:
        R -
        C -
        Parameters:
        data -
        Returns:
      • cov2cor

        public static cern.colt.matrix.DoubleMatrix2D cov2cor​(cern.colt.matrix.DoubleMatrix2D cov)
        Scale a covariance matrix to the corresponding correlation matrix.
        Parameters:
        cov - a symmetric matrix of covariances
        Returns:
      • unLogTransform

        public static <R,​C> void unLogTransform​(DoubleMatrix<R,​C> matrix)
        Undo log2 transform.
        Type Parameters:
        R -
        C -
        Parameters:
        matrix -