Class MatrixUtil

java.lang.Object
ubic.basecode.dataStructure.matrix.MatrixUtil

public class MatrixUtil extends Object
Author:
Paul
  • Constructor Details

    • MatrixUtil

      public MatrixUtil()
  • Method Details

    • containsNearlyZeros

      public static boolean containsNearlyZeros(DoubleMatrix1D d)
      Parameters:
      d -
      Returns:
      true if any of the values are very close to zero.
    • diagonal

      public static DoubleMatrix1D diagonal(DoubleMatrix2D matrix)
      Extract the diagonal from a matrix.
      Parameters:
      matrix -
      Returns:
    • dropColumn

      public static DoubleMatrix2D dropColumn(DoubleMatrix2D n, int indexToDrop)
      Parameters:
      n -
      indexToDrop -
      Returns:
    • dropColumns

      public static DoubleMatrix2D dropColumns(DoubleMatrix2D n, Collection<Integer> droppedColumns)
      Parameters:
      n -
      droppedColumns -
    • fromList

      public static DoubleMatrix1D fromList(DoubleArrayList list)
      Makes a copy
      Parameters:
      list -
      Returns:
    • getObject

      public static <R, C, V> V getObject(Matrix2D<R,C,V> matrix, int rowIndex, int colIndex)
      Type Parameters:
      R -
      C -
      V -
      Parameters:
      matrix -
      rowIndex -
      colIndex -
      Returns:
    • getRow

      public static <R, C, V> V[] getRow(Matrix2D<R,C,V> matrix, int rowIndex)
      Type Parameters:
      R -
      C -
      V -
      Parameters:
      matrix -
      rowIndex -
      Returns:
    • maskMissing

      public static void maskMissing(DoubleMatrix2D source, DoubleMatrix2D target)
      Parameters:
      source - the source of information about missing values
      target - the target where we want to convert values to missing
    • multWithMissing

      public static DoubleMatrix1D multWithMissing(DoubleMatrix1D a, DoubleMatrix2D b)
    • multWithMissing

      public static DoubleMatrix1D multWithMissing(DoubleMatrix2D a, DoubleMatrix1D b)
      Parameters:
      a -
      b -
      Returns:
    • multWithMissing

      public static DoubleMatrix2D multWithMissing(DoubleMatrix2D a, DoubleMatrix2D b)
      Multiple two matrices, tolerate missing values.
      Parameters:
      a -
      b -
      Returns:
    • notNearlyZeroIndices

      public static List<Integer> notNearlyZeroIndices(DoubleMatrix1D d)
    • removeMissingOrInfinite

      public static DoubleMatrix1D removeMissingOrInfinite(DoubleMatrix1D data)
      Parameters:
      data -
      Returns:
      a copy of the data with missing or infinite values removed (might be empty!)
    • removeMissing

      public static final DoubleMatrix1D removeMissing(DoubleMatrix1D x)
      Parameters:
      x -
      Returns:
      a copy of x with missing values removed
    • removeMissingOrInfinite

      public static DoubleMatrix1D removeMissingOrInfinite(DoubleMatrix1D reference, DoubleMatrix1D data)
      Remove values from data corresponding to missing values in reference.
      Parameters:
      reference -
      data -
      Returns:
    • stripNegative

      public static final DoubleMatrix1D stripNegative(DoubleMatrix1D x)
    • stripByCriterion

      public static final DoubleMatrix1D stripByCriterion(DoubleMatrix1D x, DoubleFunction<Boolean> criterion)
    • conjunction

      public static final BooleanArrayList conjunction(BooleanArrayList a, BooleanArrayList b)
      Compute the conjuction (logical 'and') of two boolean vectors
      Parameters:
      a -
      b -
      Returns:
      conjunction of a and b
    • matchingCriteria

      public static BooleanArrayList matchingCriteria(DoubleMatrix1D x, DoubleFunction<Boolean> criterion)
      Parameters:
      x - vector to be operated on
      criterion - a function that returns a boolean if a double matches the desired criteria
      Returns:
      booleans indicating which values in x match the criterion func
    • applyToIndicesMatchingCriteria

      public static DoubleMatrix1D applyToIndicesMatchingCriteria(DoubleMatrix1D x, DoubleFunction<Boolean> criterion, DoubleFunction<Double> action)
      Parameters:
      x - vector to be operated on
      criterion - criterion used to test values if they should be acted on.
      action - function applied to values if they match the criterion
      Returns:
      copy of x in which the values meeting the criterion have been replaced with the return value of action, otherwise unchanged from the original x
    • stripNonOK

      public static final DoubleMatrix1D stripNonOK(DoubleMatrix1D x, BooleanArrayList ok)
      Parameters:
      x - a vector of values to be filtered
      ok - a list of booleans defining which values are "ok".
      Returns:
      A copy of x that has the non-ok values removed.
    • replaceValues

      public static void replaceValues(DoubleMatrix1D x, BooleanArrayList toReplace, DoubleMatrix1D replacements)
      Perform the awkward operation of substituting certain values in a vector from values in another vector.
      Parameters:
      x - vector to be operated on in place (it will be modified).
      toReplace - boolean indicators of same length of x, 'true' indicates a value to be replaced in x with a value from 'replacements'; 'false' will be unmodified in x.
      replacements - the replacements, in order, to be substituted in x where toReplace(i) is true. This vector can be shorter than x.
    • select

      public static DoubleMatrix1D select(DoubleMatrix1D v, Collection<Integer> selected)
    • selectColumns

      public static DoubleMatrix2D selectColumns(DoubleMatrix2D n, Collection<Integer> selected)
    • selectColumnsAndRows

      public static DoubleMatrix2D selectColumnsAndRows(DoubleMatrix2D n, Collection<Integer> selected)
      Parameters:
      n - square matrix
      selected -
      Returns:
    • selectRows

      public static DoubleMatrix2D selectRows(DoubleMatrix2D n, Collection<Integer> selected)
    • sizeWithoutMissingValues

      public static int sizeWithoutMissingValues(DoubleMatrix1D list)
    • toList

      public static DoubleArrayList toList(DoubleMatrix1D vector)
      Makes a copy
      Parameters:
      vector -
      Returns: