Class ProcessPythonCiService

java.lang.Object
edu.cmu.tetrad.search.test.ProcessPythonCiService
All Implemented Interfaces:
PythonCiService, Closeable, AutoCloseable

public final class ProcessPythonCiService extends Object implements PythonCiService
Spawns a persistent Python process running kci_server.py and communicates using JSONL over stdin/stdout. Intended for experimentation / profiling, not a hardened production transport.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ProcessPythonCiService(String pythonExe, String serverScriptPath)
    Constructor for ProcessPythonCiService, which sets up the Python executable and the server script path for the service.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    void
    initializeIfNeeded(DataSet data, List<Node> vars, Map<String,Object> kciParams)
    Prepares the service for operation if it has not been initialized yet.
    double
    pValue(int xIndex, int yIndex, int[] zIndices, double alpha)
    Computes the p-value for a conditional independence test based on the specified variables and parameters.
    void
    setVerbose(boolean verbose)
    Sets the verbosity mode for the service.
    void
    Updates the parameters for the service with the provided map of key-value pairs.

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ProcessPythonCiService

      public ProcessPythonCiService(String pythonExe, String serverScriptPath)
      Constructor for ProcessPythonCiService, which sets up the Python executable and the server script path for the service.
      Parameters:
      pythonExe - the path to the Python executable. Must nojt be null or empty.
      serverScriptPath - the path to the Python server script. Must not be null or empty.
      Throws:
      NullPointerException - if either pythonExe or serverScriptPath is null.
      IllegalArgumentException - if either pythonExe or serverScriptPath is empty.
  • Method Details

    • setVerbose

      public void setVerbose(boolean verbose)
      Description copied from interface: PythonCiService
      Sets the verbosity mode for the service. When verbosity is enabled, additional logs or debug information may be emitted to assist in tracking the execution flow or diagnosing issues.
      Specified by:
      setVerbose in interface PythonCiService
      Parameters:
      verbose - a boolean flag indicating whether to enable or disable verbosity. If true, verbose output is enabled; if false, it is disabled.
    • initializeIfNeeded

      public void initializeIfNeeded(DataSet data, List<Node> vars, Map<String,Object> kciParams)
      Description copied from interface: PythonCiService
      Prepares the service for operation if it has not been initialized yet. This method ensures that the necessary state, resources, or configurations are set up based on the provided dataset, variable list, and parameters.
      Specified by:
      initializeIfNeeded in interface PythonCiService
      Parameters:
      data - the dataset on which the service operates, containing the data required for conditional independence tests.
      vars - the list of variables (nodes) relevant to the operations, representing the context in which tests or analyses are conducted.
      kciParams - a map of configuration parameters used to customize the initialization, such as specific settings for the Python backend or statistical operations.
    • updateParams

      public void updateParams(Map<String,Object> kciParams)
      Description copied from interface: PythonCiService
      Updates the parameters for the service with the provided map of key-value pairs. This method allows customization or reconfiguration of the service at runtime by changing its operational parameters.
      Specified by:
      updateParams in interface PythonCiService
      Parameters:
      kciParams - a map containing key-value pairs representing the parameters to be updated. Each key is a string identifying the parameter, and the associated value determines the new configuration or setting to be applied.
    • pValue

      public double pValue(int xIndex, int yIndex, int[] zIndices, double alpha)
      Description copied from interface: PythonCiService
      Computes the p-value for a conditional independence test based on the specified variables and parameters. The method evaluates whether the variables indexed by xIndex and yIndex are conditionally independent given the variables indexed by zIndices.
      Specified by:
      pValue in interface PythonCiService
      Parameters:
      xIndex - the index of the first variable in the conditional independence test.
      yIndex - the index of the second variable in the conditional independence test.
      zIndices - an array of indices representing the conditioning set of variables.
      alpha - the significance level used for the test, helping to determine the threshold for rejecting the null hypothesis of independence.
      Returns:
      a double representing the p-value of the conditional independence test. A smaller p-value indicates stronger evidence against the null hypothesis of independence.
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException