KCI Test module

causalai.models.common.CI_tests.kci

class causalai.models.common.CI_tests.kci.KCI(Xkernel: ~causalai.models.common.CI_tests.kernels.KernelBase = <causalai.models.common.CI_tests.kernels.GaussianKernel object>, Ykernel: ~causalai.models.common.CI_tests.kernels.KernelBase = <causalai.models.common.CI_tests.kernels.GaussianKernel object>, Zkernel: ~causalai.models.common.CI_tests.kernels.KernelBase = <causalai.models.common.CI_tests.kernels.GaussianKernel object>, null_space_size: int = 5000, approx: bool = True, chunk_size: int = 1000)

Kernel-based Conditional Independence (KCI) test. Original implementation: http://people.tuebingen.mpg.de/kzhang/KCI-test.zip

References

[1] K. Zhang, J. Peters, D. Janzing, and B. Schölkopf, "A kernel-based conditional independence test and application in causal discovery," In UAI 2011.

__init__(Xkernel: ~causalai.models.common.CI_tests.kernels.KernelBase = <causalai.models.common.CI_tests.kernels.GaussianKernel object>, Ykernel: ~causalai.models.common.CI_tests.kernels.KernelBase = <causalai.models.common.CI_tests.kernels.GaussianKernel object>, Zkernel: ~causalai.models.common.CI_tests.kernels.KernelBase = <causalai.models.common.CI_tests.kernels.GaussianKernel object>, null_space_size: int = 5000, approx: bool = True, chunk_size: int = 1000)

KCI test constructor.

Parameters:
  • Xkernel (KernelBase object) -- kernel class instance for input data x. Available options are GaussianKernel and LinearKernel.

  • Ykernel (KernelBase object) -- kernel class instance for input data y. Available options are GaussianKernel and LinearKernel.

  • Zkernel (KernelBase object) -- kernel class instance for input data z (conditional variables). Available options are GaussianKernel and LinearKernel.

  • null_space_size (int) -- sample size in simulating the null distribution (default=5000).

  • approx (bool) -- whether to use gamma approximation (default=True).

  • chunk_size (int) -- if number of data samples is more than chunk_size (default=1000), only extract the block-wise diagonal kernel matrix of the full kernel matrix to save memory and computation.

run_test(data_x: ndarray | None = None, data_y: ndarray | None = None, data_z: ndarray | None = None) Tuple[float, float]

compute the test statistics and pvalues

Parameters:
  • data_x (ndarray) -- input data for x

  • data_y (ndarray) -- input data for y

  • data_z (ndarray) -- input data for z

Returns:

Returns a tuple of 2 floats-- test statistic and the corresponding pvalue

Return type:

tuple of floats