Class TestwiseRows
java.lang.Object
edu.cmu.tetrad.data.missing.TestwiseRows
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 TypeMethodDescriptionintThe number of column sets currently cached.voidClears this dataset's cache.static TestwiseRowsforDataSet(DataSet dataSet) Returns the (shared, cached) instance for the given dataset, creating it if necessary.static TestwiseRowsReturns the (shared, cached) instance for the given raw data matrix, in which missing entries are NaN, creating it if necessary.static voidinvalidate(DataSet dataSet) 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.The rows on which every one of the given columns is observed, in increasing order, as an immutable list.
-
Method Details
-
forDataSet
Returns the (shared, cached) instance for the given dataset, creating it if necessary.- Parameters:
dataSet- The dataset.- Returns:
- This instance.
-
forMatrix
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
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
The rows on which every one of the given columns is observed, in increasing order, as an immutable list. WhencandidateRowsis 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
-
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.
-