Package edu.cmu.tetrad.search.test
Class CachingIndependenceTest
java.lang.Object
edu.cmu.tetrad.search.test.CachingIndependenceTest
- All Implemented Interfaces:
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 Summary
ConstructorsConstructorDescriptionConstructs a caching wrapper for an IndependenceTest. -
Method Summary
Modifier and TypeMethodDescriptioncheckIndependence(Node x, Node y, Set<Node> z) Evaluates the conditional independence between two nodes given a condition set of nodes.Retrieves the underlying IndependenceTest instance used within the CachingIndependenceTest.getData()Retrieves the data model associated with the underlying independence test.Retrieves the list of variables from the underlying independence test.booleanDetermines whether the underlying independence test is in verbose mode.voidsetVerbose(boolean verbose) Sets the verbosity mode for the underlying independence test.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface edu.cmu.tetrad.search.test.IndependenceTest
checkIndependence, determines, getAlpha, getCov, getDataSets, getSampleSize, getVariable, getVariableNames, indTestSubset, setAlpha, toString
-
Constructor Details
-
CachingIndependenceTest
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
Retrieves the list of variables from the underlying independence test.- Specified by:
getVariablesin interfaceIndependenceTest- Returns:
- A list of
Nodeobjects representing the variables associated with the independence test.
-
getData
Retrieves the data model associated with the underlying independence test.- Specified by:
getDatain interfaceIndependenceTest- Returns:
- A
DataModelobject 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:
isVerbosein interfaceIndependenceTest- 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:
setVerbosein interfaceIndependenceTest- 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:
checkIndependencein interfaceIndependenceTest- 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
IndependenceResultobject 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
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
IndependenceTestinstance.
-