Class CachingIndependenceTest

java.lang.Object
edu.cmu.tetrad.search.test.CachingIndependenceTest
All Implemented Interfaces:
IndependenceTest

public class CachingIndependenceTest extends Object implements IndependenceTest
A caching wrapper for IndependenceTest.

Ensures that each unique conditional independence test (X _||_ Y | Z) is evaluated at most once. Results are cached and re-used. Both (X,Y|Z) and (Y,X|Z) map to the same cache entry.

Useful for expensive tests such as KCI.

  • Constructor Details

    • CachingIndependenceTest

      public CachingIndependenceTest(IndependenceTest base)
      Constructs a caching wrapper for an IndependenceTest. This wrapper ensures that each unique conditional independence test is evaluated at most once, caching and reusing existing results.
      Parameters:
      base - The underlying IndependenceTest to be wrapped, which performs the actual independence tests.
      Throws:
      NullPointerException - if the provided base test is null.
  • Method Details

    • getVariables

      public List<Node> getVariables()
      Retrieves the list of variables from the underlying independence test.
      Specified by:
      getVariables in interface IndependenceTest
      Returns:
      A list of Node objects representing the variables associated with the independence test.
    • getData

      public DataModel getData()
      Retrieves the data model associated with the underlying independence test.
      Specified by:
      getData in interface IndependenceTest
      Returns:
      A DataModel object representing the data model.
    • isVerbose

      public boolean isVerbose()
      Determines whether the underlying independence test is in verbose mode. Verbose mode typically indicates that additional information or output may be generated by the underlying test for debugging or logging purposes.
      Specified by:
      isVerbose in interface IndependenceTest
      Returns:
      true if verbose mode is enabled; false otherwise.
    • setVerbose

      public void setVerbose(boolean verbose)
      Sets the verbosity mode for the underlying independence test. When verbose mode is enabled, additional information or output may be generated for debugging or logging purposes.
      Specified by:
      setVerbose in interface IndependenceTest
      Parameters:
      verbose - true to enable verbose mode; false to disable it.
    • checkIndependence

      public IndependenceResult checkIndependence(Node x, Node y, Set<Node> z) throws InterruptedException
      Evaluates the conditional independence between two nodes given a condition set of nodes. This method caches results to avoid recomputation for identical queries.
      Specified by:
      checkIndependence in interface IndependenceTest
      Parameters:
      x - The first node being tested for independence.
      y - The second node being tested for independence.
      z - The set of nodes that establishes the condition under which the independence is tested.
      Returns:
      An IndependenceResult object containing the result of the independence test, including whether independence holds, the p-value, and other related information.
      Throws:
      InterruptedException - If the testing process is interrupted.
    • getBaseTest

      public IndependenceTest getBaseTest()
      Retrieves the underlying IndependenceTest instance used within the CachingIndependenceTest. This method provides access to the base test that performs the actual independence evaluations.
      Returns:
      The underlying IndependenceTest instance.
    • getAlpha

      public double getAlpha()
      Returns the alpha of the base test. Without this delegation, consumers relying on alpha (for instance, MarkovCheck's statistics) fail with UnsupportedOperationException when handed a cached test.
      Specified by:
      getAlpha in interface IndependenceTest
      Returns:
      the base test's alpha.
    • setAlpha

      public void setAlpha(double alpha)
      Sets the alpha of the base test and clears the cache, since cached independence judgments were made under the previous alpha and would otherwise be returned inconsistently.
      Specified by:
      setAlpha in interface IndependenceTest
      Parameters:
      alpha - the new alpha.
    • getSampleSize

      public int getSampleSize()
      Returns the sample size of the base test.
      Specified by:
      getSampleSize in interface IndependenceTest
      Returns:
      the base test's sample size.
    • getCov

      public ICovarianceMatrix getCov()
      Returns the covariance matrix of the base test.
      Specified by:
      getCov in interface IndependenceTest
      Returns:
      the base test's covariance matrix.
    • getDataSets

      public List<DataSet> getDataSets()
      Returns the datasets of the base test.
      Specified by:
      getDataSets in interface IndependenceTest
      Returns:
      the base test's datasets.