Class PythonKciIndependenceTest
java.lang.Object
edu.cmu.tetrad.search.test.PythonKciIndependenceTest
- All Implemented Interfaces:
IndependenceTest, Closeable, AutoCloseable
The PythonKciIndependenceTest class implements an independence test using the kernel
conditional independence (KCI) test provided through a Python backend, such as
causallearn. It facilitates independence determination between variables of a given
dataset and manages interaction with the associated Python service.
This class is immutable except for certain configurable properties (e.g., alpha, verbosity).
It initializes resources on the Python side upon instantiation and provides mechanisms
to perform independence testing, adjust parameters, and release resources when no longer needed.
Thread Safety:
- The class is thread-safe for concurrent read/query operations.
- Care is required when modifying properties (alpha, verbosity, or KCI parameters),
as intended thread-safety for setters is only provided via `volatile` or synchronized service updates.
- The service interactions must ensure proper thread coordination.
Responsibilities:
- Maps dataset variables to indices for Python integration.
- Executes the KCI test by delegating the computation to the Python service.
- Manages test parameters such as significance level (alpha) and verbosity.
- Facilitates resource cleanup by implementing the Closeable interface.
-
Constructor Summary
ConstructorsConstructorDescriptionPythonKciIndependenceTest(DataSet data, PythonCiService service) Constructs a PythonKciIndependenceTest object for performing conditional independence tests using a Python backend via the provided PythonCiService. -
Method Summary
Modifier and TypeMethodDescriptioncheckIndependence(Node x, Node y, Set<Node> z) Tests the conditional independence between two variables given a conditioning set, using a Python backend for statistical computations.voidclose()Closes the underlying PythonCiService associated with this instance, releasing any resources and terminating any persistent connections.doublegetAlpha()Retrieves the significance level (alpha) used in conditional independence tests.getData()Retrieves the data model associated with this instance.Retrieves the list of variables involved in the analysis.booleanIndicates whether verbose output is enabled for the PythonKciIndependenceTest.voidsetAlpha(double alpha) Sets the significance level (alpha) used in conditional independence tests.voidsetKciParam(String key, Object value) Sets a KCI-specific parameter for the PythonKciIndependenceTest instance.voidsetVerbose(boolean verbose) Sets whether verbose output is enabled for this instance of PythonKciIndependenceTest.toString()Returns a string representation of the PythonKciIndependenceTest instance, providing a concise description intended to identify the use of the KCI method for causal independence tests integrated with a Python backend.Methods inherited from interface IndependenceTest
canBeSubsampled, checkIndependence, determines, getCov, getDataSets, getMissingValueSupport, getSampleSize, getVariable, getVariableNames, indTestSubset, isPValueAProbability
-
Constructor Details
-
PythonKciIndependenceTest
Constructs a PythonKciIndependenceTest object for performing conditional independence tests using a Python backend via the provided PythonCiService. The method initializes required fields and prepares the object for subsequent operations.- Parameters:
data- the dataset containing the variables and relationships to analyze; must not be nullservice- the PythonCiService used to execute independence tests in a Python environment; must not be null
-
-
Method Details
-
checkIndependence
public IndependenceResult checkIndependence(Node x, Node y, Set<Node> z) throws InterruptedException Tests the conditional independence between two variables given a conditioning set, using a Python backend for statistical computations. Computes the p-value for the hypothesis that the variables are conditionally independent, and determines whether to reject the null hypothesis based on a specified significance level (alpha).- Specified by:
checkIndependencein interfaceIndependenceTest- Parameters:
x- the first variable (Node) for testing conditional independence; must not be nully- the second variable (Node) for testing conditional independence; must not be nullz- the conditioning set (Set of Node) on which the independence hypothesis is conditioned; can be null or empty- Returns:
- an IndependenceResult containing the outcome of the test, including the computed p-value, whether the null hypothesis was rejected, and a related score
- Throws:
InterruptedException- if the thread running this method is interrupted
-
getVariables
Retrieves the list of variables involved in the analysis.- Specified by:
getVariablesin interfaceIndependenceTest- Returns:
- a list of Node objects representing the variables in the dataset.
-
getData
Retrieves the data model associated with this instance.- Specified by:
getDatain interfaceIndependenceTest- Returns:
- the DataModel object representing the dataset used for analysis.
-
isVerbose
public boolean isVerbose()Indicates whether verbose output is enabled for the PythonKciIndependenceTest.- Specified by:
isVerbosein interfaceIndependenceTest- Returns:
- true if verbose output is enabled, false otherwise
-
setVerbose
public void setVerbose(boolean verbose) Sets whether verbose output is enabled for this instance of PythonKciIndependenceTest. When verbosity is enabled, additional details about the operations performed by the Python backend may be provided in the output.- Specified by:
setVerbosein interfaceIndependenceTest- Parameters:
verbose- a boolean value indicating whether verbose output should be enabled (true) or disabled (false)
-
getAlpha
public double getAlpha()Retrieves the significance level (alpha) used in conditional independence tests. The alpha value represents the threshold for deciding whether to reject the null hypothesis of conditional independence.- Specified by:
getAlphain interfaceIndependenceTest- Returns:
- the alpha value as a double, representing the significance level for the tests
-
setAlpha
public void setAlpha(double alpha) Sets the significance level (alpha) used in conditional independence tests. The alpha value determines the threshold for rejecting the null hypothesis of conditional independence. A lower alpha value indicates a stricter criterion for concluding that two variables are not conditionally independent.- Specified by:
setAlphain interfaceIndependenceTest- Parameters:
alpha- the significance level to be set; must be a double value between 0 and 1 (exclusive) representing the desired confidence level
-
close
public void close()Closes the underlying PythonCiService associated with this instance, releasing any resources and terminating any persistent connections. This method ensures that the external Python backend for performing conditional independence tests is properly shut down. If an IOException occurs during the closing process, it will be wrapped and propagated as a RuntimeException.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
RuntimeException- if an IOException is encountered while closing the service
-
toString
Returns a string representation of the PythonKciIndependenceTest instance, providing a concise description intended to identify the use of the KCI method for causal independence tests integrated with a Python backend.- Specified by:
toStringin interfaceIndependenceTest- Overrides:
toStringin classObject- Returns:
- a string describing the PythonKciIndependenceTest implementation.
-
setKciParam
Sets a KCI-specific parameter for the PythonKciIndependenceTest instance. This method allows users to modify or add configuration parameters specific to the Kernel-based Conditional Independence method. Once a parameter is updated, the changes are propagated to the underlying Python service responsible for performing conditional independence tests.- Parameters:
key- the name of the parameter to set; must not be nullvalue- the value to assign to the specified parameter; can be any object representing the desired parameter value, depending on the expected type of the parameter
-