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 to getTest(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 has causal-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:
  1. If Params.PYTHON_CI_SERVER is set to a non-empty path (and not the sentinel value "Use bundled script"), that path is used directly.
  2. Otherwise, the bundled resource python/kci_server.py is extracted to the user's local cache directory (via PythonResource.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 — if true, the test logs additional detail during execution (default: false).

Data

Only continuous DataSet inputs are supported. Passing any other DataModel type will throw an IllegalArgumentException.
See Also:
  • Constructor Details

    • ClKciPython

      public ClKciPython()
      Default constructor for the ClKciPython class. This constructor initializes an instance of the ClKciPython class.
  • Method Details

    • getTest

      public IndependenceTest getTest(DataModel dataModel, Parameters parameters)
      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:
      getTest in interface IndependenceWrapper
      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

      public String getDescription()
      Provides a description of the test being implemented by the ClKciPython class.
      Specified by:
      getDescription in interface IndependenceWrapper
      Returns:
      A string representing the description of the test, specifically "KCI-CL (Python)".
    • getDataType

      public DataType 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:
      getDataType in interface IndependenceWrapper
      Returns:
      The data type of this implementation. In this case, the data type is DataType.Continuous.
    • getParameters

      public List<String> 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:
      getParameters in interface HasParameters
      Specified by:
      getParameters in interface IndependenceWrapper
      Returns:
      A list of strings representing the names of parameters necessary for configuring the test implemented by the ClKciPython class.