Class TestwiseRows

java.lang.Object
edu.cmu.tetrad.data.missing.TestwiseRows

public final class TestwiseRows extends Object
Computes, and caches, the row subsets used by test-wise deletion: for a given set of columns, the rows of a dataset on which all of those columns are observed. Searches ask for the same local row subsets repeatedly (every local score or independence test involving the same variable set needs the same rows), and recomputing them is the main overhead of the test-wise path; this class computes each subset once per column set.

Instances are obtained per dataset from forDataSet(DataSet), which maintains a weak registry so that a score and a test running on the same dataset share one cache, and so that caches are garbage-collected with their datasets. Caching is on by default. The cache does not observe mutations to the dataset; if a dataset is modified in place after rows have been cached, call clearCache() (or invalidate(DataSet)).

"Missing" is defined by MissingDataAudit.isMissing(DataSet, int, int): NaN for continuous variables and DiscreteVariable.MISSING_VALUE for discrete variables, so this class serves the continuous, discrete, and mixed cases uniformly.

Version:
$Id: $Id
Author:
josephramsey
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    The number of column sets currently cached.
    void
    Clears this dataset's cache.
    Returns the (shared, cached) instance for the given dataset, creating it if necessary.
    forMatrix(Matrix matrix)
    Returns the (shared, cached) instance for the given raw data matrix, in which missing entries are NaN, creating it if necessary.
    static void
    Discards any cached instance for the given dataset.
    validRows(int[] columns)
    The rows on which every one of the given columns is observed, over all rows of the dataset, cached.
    validRows(int[] columns, List<Integer> candidateRows)
    The rows on which every one of the given columns is observed, in increasing order, as an immutable list.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • forDataSet

      public static TestwiseRows forDataSet(DataSet dataSet)
      Returns the (shared, cached) instance for the given dataset, creating it if necessary.
      Parameters:
      dataSet - The dataset.
      Returns:
      This instance.
    • forMatrix

      public static TestwiseRows forMatrix(Matrix matrix)
      Returns the (shared, cached) instance for the given raw data matrix, in which missing entries are NaN, creating it if necessary. Keyed on matrix identity.
      Parameters:
      matrix - The matrix.
      Returns:
      This instance.
    • invalidate

      public static void invalidate(DataSet dataSet)
      Discards any cached instance for the given dataset. Call this if a dataset has been mutated in place after analysis began.
      Parameters:
      dataSet - The dataset.
    • validRows

      public List<Integer> validRows(int[] columns, List<Integer> candidateRows)
      The rows on which every one of the given columns is observed, in increasing order, as an immutable list. When candidateRows is null or spans the whole dataset, the result is cached per column set; when a proper subset of rows is supplied (e.g., by a subsampling search via RowsSettable), the result is computed directly without caching, since such subsets change from call to call.
      Parameters:
      columns - The column indices; need not be sorted or distinct.
      candidateRows - The rows to restrict attention to, or null for all rows.
      Returns:
      This list.
    • validRows

      public List<Integer> validRows(int[] columns)
      The rows on which every one of the given columns is observed, over all rows of the dataset, cached.
      Parameters:
      columns - The column indices; need not be sorted or distinct.
      Returns:
      This list, immutable and in increasing order.
    • clearCache

      public void clearCache()
      Clears this dataset's cache. Call this if the dataset has been mutated in place after analysis began.
    • cacheSize

      public int cacheSize()
      The number of column sets currently cached. Exposed for testing.
      Returns:
      This count.