Class ClKciPython
java.lang.Object
edu.cmu.tetrad.algcomparison.independence.ClKciPython
- All Implemented Interfaces:
IndependenceWrapper, HasParameters, TetradSerializable, Serializable
@TestOfIndependence(name="KCI, Causal Learn (Python)",
command="kci-cl-test",
dataType=Continuous)
@General
public class ClKciPython
extends Object
implements IndependenceWrapper
An
IndependenceWrapper that runs the Kernel-based Conditional Independence (KCI)
test implemented in the Python causal-learn library, bridging it into Tetrad's
IndependenceTest framework.
How it works
Each call togetTest(DataModel, Parameters) launches (or connects to) a persistent Python process
running a bundled server script (python/kci_server.py). CI queries from Java
are forwarded to that process via ProcessPythonCiService, and results are
returned as standard IndependenceTest responses through
PythonKciIndependenceTest.
Python environment
A Python interpreter that hascausal-learn and its dependencies installed must
be available on the host machine. The path to that interpreter is supplied via the
Params.PYTHON_EXE parameter. There is no default that is likely to be valid on
any machine other than the developer's, so this parameter should always be set
explicitly before use.
Server script resolution
The Python server script is resolved in the following order:- If
Params.PYTHON_CI_SERVERis set to a non-empty path (and not the sentinel value"Use bundled script"), that path is used directly. - Otherwise, the bundled resource
python/kci_server.pyis extracted to the user's local cache directory (viaPythonResource.extractToUserCache(String, String)) and that extracted copy is used.
Parameters
Params.PYTHON_EXE— path to the Python executable (required).Params.PYTHON_CI_SERVER— path to the KCI server script, or"Use bundled script"to use the packaged default.Params.ALPHA— significance level for the independence test (default:0.01).Params.VERBOSE— iftrue, the test logs additional detail during execution (default:false).
Data
Only continuousDataSet inputs are supported. Passing any other
DataModel type will throw an IllegalArgumentException.- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the data type associated with this implementation.Provides a description of the test being implemented by the ClKciPython class.Retrieves the list of parameters required for the configuration of the ClKciPython test.getTest(DataModel dataModel, Parameters parameters) Creates and returns an IndependenceTest instance using the provided DataModel and Parameters.
-
Constructor Details
-
ClKciPython
public ClKciPython()Default constructor for the ClKciPython class. This constructor initializes an instance of the ClKciPython class.
-
-
Method Details
-
getTest
Creates and returns an IndependenceTest instance using the provided DataModel and Parameters. The method ensures that the appropriate Python executable and server script are properly configured, resolving paths as necessary. A ProcessPythonCiService instance is initialized, and its output is used to create a PythonKciIndependenceTest with configurable settings such as alpha and verbosity.- Specified by:
getTestin interfaceIndependenceWrapper- Parameters:
dataModel- The data model to be analyzed. Must be an instance of DataSet (continuous).parameters- Configuration parameters for the test, including paths for the Python executable and server script, as well as settings like alpha and verbosity.- Returns:
- An IndependenceTest instance configured using the provided dataModel and parameters.
- Throws:
IllegalArgumentException- If the dataModel is not an instance of DataSet, the Python executable path is invalid or missing, or the server script path is invalid.RuntimeException- If there is an error extracting the bundled Python server script.
-
getDescription
Provides a description of the test being implemented by the ClKciPython class.- Specified by:
getDescriptionin interfaceIndependenceWrapper- Returns:
- A string representing the description of the test, specifically "KCI-CL (Python)".
-
getDataType
Returns the data type associated with this implementation. The data type indicates the type of data that the method operates on or supports.- Specified by:
getDataTypein interfaceIndependenceWrapper- Returns:
- The data type of this implementation. In this case, the data type
is
DataType.Continuous.
-
getParameters
Retrieves the list of parameters required for the configuration of the ClKciPython test. These parameters may include settings such as the alpha level, Python executable, Python CI server path, and verbosity.- Specified by:
getParametersin interfaceHasParameters- Specified by:
getParametersin interfaceIndependenceWrapper- Returns:
- A list of strings representing the names of parameters necessary for configuring the test implemented by the ClKciPython class.
-