Class ClFisherZPython

java.lang.Object
edu.cmu.tetrad.algcomparison.independence.ClFisherZPython
All Implemented Interfaces:
IndependenceWrapper, HasParameters, TetradSerializable, Serializable

@TestOfIndependence(name="Fisher Z, Causal Learn (Python)", command="fisherz-cl-test", dataType=Continuous) @General public class ClFisherZPython extends Object implements IndependenceWrapper
An IndependenceWrapper that runs the Fisher Z conditional independence 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/fisherz_server.py). CI queries from Java are forwarded to that process via ProcessPythonCiService, and results are returned as standard IndependenceTest responses through PythonRcitIndependenceTest.

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/fisherz_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 Fisher Z 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

    • ClFisherZPython

      public ClFisherZPython()
      Default constructor for the ClFisherZPython class. This constructor initializes an instance of the ClFisherZPython class, which serves as a wrapper and utility for performing independence tests using Python-based methods. It does not take any parameters or perform any custom initialization logic.
  • Method Details

    • getTest

      public IndependenceTest getTest(DataModel dataModel, Parameters parameters)
      Retrieves an independence test based on the provided data model and parameters. The method specifically requires a continuous DataSet and utilizes a Python-based process to perform the independence test.
      Specified by:
      getTest in interface IndependenceWrapper
      Parameters:
      dataModel - the input data model, must be an instance of DataSet
      parameters - an optional collection of configuration parameters, used to customize the Python executable path, server script location, alpha threshold, and verbosity settings
      Returns:
      an instance of IndependenceTest configured with the provided data model and parameters
      Throws:
      IllegalArgumentException - if the provided dataModel is not a continuous DataSet or if required parameters are invalid
      RuntimeException - if the bundled Python server script cannot be extracted
    • getDescription

      public String getDescription()
      Provides a textual description of the test implementation.
      Specified by:
      getDescription in interface IndependenceWrapper
      Returns:
      a string describing the test, "FisherZ-CL (Python)"
    • getDataType

      public DataType getDataType()
      Retrieves the data type associated with the test.
      Specified by:
      getDataType in interface IndependenceWrapper
      Returns:
      the data type of the test, which is DataType.Continuous
    • getParameters

      public List<String> getParameters()
      Retrieves a list of parameter names required for the Python-based independence test.
      Specified by:
      getParameters in interface HasParameters
      Specified by:
      getParameters in interface IndependenceWrapper
      Returns:
      a list of parameter names as strings, including: ALPHA, PYTHON_EXE, PYTHON_CI_SERVER, and VERBOSE.