Class AdTree

java.lang.Object
edu.cmu.tetrad.search.utils.AdTree

public class AdTree extends Object
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 Details

    • AdTree

      public AdTree(DataSet dataSet)
      Constructs an AdTreeCount for the given dataset using all rows.
      Parameters:
      dataSet - A discrete dataset.
    • AdTree

      public AdTree(DataSet dataSet, List<Integer> rows)
      Constructs an AdTreeCount for the given dataset and row subset.
      Parameters:
      dataSet - A discrete dataset.
      rows - The rows to use; if null, all rows are used.
    • AdTree

      public AdTree(int[][] discreteData, Map<Node,Integer> nodesHash, List<Integer> rows, int numRows)
      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

      public void buildTable(List<DiscreteVariable> variables)
      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

      public Map<Node,Integer> getNodesHash()
      Returns the nodes hash, for sharing across bootstrap instances.
      Returns:
      The nodes hash.