Class AdTree
java.lang.Object
edu.cmu.tetrad.search.utils.AdTree
A count-only variant of AdTree. Instead of storing the full list of row indices in each
subdivision (cell), this class stores only the count of rows. This makes the cache entries
O(1) in memory rather than O(n), making it practical for large datasets and bootstrap contexts
where the full AdTree cache would cause severe GC pressure.
The tradeoff is that getCell() is not supported -- only counts are available.
- Author:
- josephramsey 2024-9-1 (refactored from AdTree)
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs an AdTreeCount using pre-initialized discrete data, avoiding re-scanning the dataset.Constructs an AdTreeCount for the given dataset using all rows.Constructs an AdTreeCount for the given dataset and row subset. -
Method Summary
Modifier and TypeMethodDescriptionvoidbuildTable(List<DiscreteVariable> variables) Builds the count table for the given variables.voidClears the cache.intgetCellIndex(int... coords) Returns the cell index for the given coordinates.intgetCount(int[] coords) Returns the count for the cell at the given coordinates.int[][]Returns the pre-built discrete data array, for sharing across bootstrap instances.Returns the nodes hash, for sharing across bootstrap instances.intReturns the total number of cells in the table.voidsetCacheDepthLimit(int cacheDepthLimit) Sets the cache depth limit.voidsetMaxCacheSize(int maxCacheSize) Sets the maximum cache size.
-
Constructor Details
-
AdTree
Constructs an AdTreeCount for the given dataset using all rows.- Parameters:
dataSet- A discrete dataset.
-
AdTree
-
AdTree
Constructs an AdTreeCount using pre-initialized discrete data, avoiding re-scanning the dataset. Use this in bootstrap contexts where only the rows change between samples.- Parameters:
discreteData- Pre-built column-major int[][] from the dataset.nodesHash- Pre-built variable to column index map.rows- The rows for this bootstrap sample.numRows- The total number of rows in the dataset (for validation).
-
-
Method Details
-
buildTable
Builds the count table for the given variables.- Parameters:
variables- The variables to build the table for.
-
getCount
public int getCount(int[] coords) Returns the count for the cell at the given coordinates.- Parameters:
coords- The coordinates of the cell.- Returns:
- The count.
-
getNumCells
public int getNumCells()Returns the total number of cells in the table.- Returns:
- The number of cells.
-
getCellIndex
public int getCellIndex(int... coords) Returns the cell index for the given coordinates.- Parameters:
coords- The coordinates.- Returns:
- The cell index.
-
setMaxCacheSize
public void setMaxCacheSize(int maxCacheSize) Sets the maximum cache size.- Parameters:
maxCacheSize- Must be >= 1.
-
setCacheDepthLimit
public void setCacheDepthLimit(int cacheDepthLimit) Sets the cache depth limit. Set to 0 to disable caching entirely.- Parameters:
cacheDepthLimit- Must be >= 0.
-
clearCache
public void clearCache()Clears the cache. Useful between bootstrap runs if sharing an instance. -
getDiscreteData
public int[][] getDiscreteData()Returns the pre-built discrete data array, for sharing across bootstrap instances.- Returns:
- The discrete data array.
-
getNodesHash
-