Package edu.cmu.tetrad.search.test
Class Kci
java.lang.Object
edu.cmu.tetrad.search.test.Kci
- All Implemented Interfaces:
IndependenceTest,RowsSettable
Gives an implementation of the Kernel Independence Test (KCI) by Kun Zhang, which is a general test of conditional
independence. The reference is here:
Zhang, K., Peters, J., Janzing, D., and Schölkopf, B. (2012). Kernel-based conditional independence test and application in causal discovery. arXiv preprint arXiv:1202.3775.
Please see that paper, especially Theorem 4 and Proposition 5.
Using optimal kernel bandwidths suggested by Silverman:
- Version:
- $Id: $Id
- Author:
- kunzhang, Vineet Raghu on 7/3/2016, josephramsey refactoring 7/4/2018, 12/6/2024
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA record representing the result of an eigenvalue decomposition.static enumRepresents the type of kernel to be used in a computation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncheckIndependence(Node x, Node y, Set<Node> z) Checks the independence between two nodes given a set of conditioning variables.doublegetAlpha()Returns the significance level of the independence test.getCov()Returns the covariance matrix.getData()Returns The data model for the independence test.Returns a list consisting of the dataset for this test.getRows()Returns the rows used in the test.intReturns the sample size.doublegetScore(IndependenceResult result) Returns alpha - p.getVariable(String name) Returns the variable of the given name.Returns the list of variables over which this independence checker is capable of determinining independence relations.indTestSubset(List<Node> vars) Returns an Independence test for a sublist of the variables.booleanReturns the value of the verbose flag.voidsetAlpha(double alpha) Sets the alpha level for the test.voidsetApproximate(boolean approximate) Sets whether the approximate algorithm should be used.voidsetKernelType(Kci.KernelType kernelType) Sets the type of kernel to be used in computations.voidsetNumBootstraps(int numBootstraps) Sets the number of bootstraps to do.voidsetPolyConst(double polyConst) Sets the constant of the polynomial kernel, if usedvoidsetPolyDegree(double polyDegree) Sets the degree of the polynomial kernel, if usedvoidAllows the user to set which rows are used in the test.voidsetScalingFactor(double scalingFactor) Sets the width multiplier.voidsetThreshold(double threshold) Sets the threshold.voidsetVerbose(boolean verbose) Sets the verbosity of the method.static org.ejml.simple.SimpleMatrixstandardizeData(org.ejml.simple.SimpleMatrix data) Standardizes the data by centering (subtracting the mean) and scaling (dividing by the standard deviation) each column of the input matrix.toString()Returns a string representation of this test.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.cmu.tetrad.search.IndependenceTest
checkIndependence, determines, getVariableNames
-
Constructor Details
-
Kci
Constructor.- Parameters:
data- The dataset to analyze. Must be continuous.alpha- The alpha value of the test.
-
-
Method Details
-
standardizeData
public static org.ejml.simple.SimpleMatrix standardizeData(org.ejml.simple.SimpleMatrix data) Standardizes the data by centering (subtracting the mean) and scaling (dividing by the standard deviation) each column of the input matrix.- Parameters:
data- the input matrix where standardization will be applied column-wise- Returns:
- a new matrix with the standardized data
-
indTestSubset
Description copied from interface:IndependenceTestReturns an Independence test for a sublist of the variables.- Specified by:
indTestSubsetin interfaceIndependenceTest- Parameters:
vars- The sublist of variables.- Returns:
- a
IndependenceTestobject - Throws:
UnsupportedOperationException- since not implemented.
-
checkIndependence
public IndependenceResult checkIndependence(Node x, Node y, Set<Node> z) throws InterruptedException Checks the independence between two nodes given a set of conditioning variables.- Specified by:
checkIndependencein interfaceIndependenceTest- Parameters:
x- The first node.y- The second node.z- The set of conditioning variables.- Returns:
- The result of the independence test.
- Throws:
InterruptedException- if any
-
getVariables
Returns the list of variables over which this independence checker is capable of determinining independence relations.- Specified by:
getVariablesin interfaceIndependenceTest- Returns:
- This list.
-
getVariable
Returns the variable of the given name.- Specified by:
getVariablein interfaceIndependenceTest- Parameters:
name- aStringobject representing the name of the variable to retrieve- Returns:
- the Node object representing the variable with the given name
-
getAlpha
public double getAlpha()Returns the significance level of the independence test.- Specified by:
getAlphain interfaceIndependenceTest- Returns:
- This alpha.
-
setAlpha
public void setAlpha(double alpha) Sets the alpha level for the test.- Specified by:
setAlphain interfaceIndependenceTest- Parameters:
alpha- The alpha level to be set.
-
toString
Returns a string representation of this test.- Specified by:
toStringin interfaceIndependenceTest- Overrides:
toStringin classObject- Returns:
- This string.
-
getData
Returns The data model for the independence test.- Specified by:
getDatain interfaceIndependenceTest- Returns:
- This data.
-
getCov
Returns the covariance matrix.- Specified by:
getCovin interfaceIndependenceTest- Returns:
- The covariance matrix.
-
getDataSets
Returns a list consisting of the dataset for this test.- Specified by:
getDataSetsin interfaceIndependenceTest- Returns:
- This dataset in a list.
-
getSampleSize
public int getSampleSize()Returns the sample size.- Specified by:
getSampleSizein interfaceIndependenceTest- Returns:
- This size.
-
getScore
Returns alpha - p.- Parameters:
result- aIndependenceResultobject- Returns:
- This number.
-
setApproximate
public void setApproximate(boolean approximate) Sets whether the approximate algorithm should be used.- Parameters:
approximate- True, if so.
-
setScalingFactor
public void setScalingFactor(double scalingFactor) Sets the width multiplier.- Parameters:
scalingFactor- This multipler.
-
setNumBootstraps
public void setNumBootstraps(int numBootstraps) Sets the number of bootstraps to do.- Parameters:
numBootstraps- This number.
-
setThreshold
public void setThreshold(double threshold) Sets the threshold.- Parameters:
threshold- This number.
-
isVerbose
public boolean isVerbose()Returns the value of the verbose flag.- Specified by:
isVerbosein interfaceIndependenceTest- Returns:
- The value of the verbose flag.
-
setVerbose
public void setVerbose(boolean verbose) Sets the verbosity of the method.- Specified by:
setVerbosein interfaceIndependenceTest- Parameters:
verbose- True if verbosity is enabled, false otherwise.
-
setKernelType
Sets the type of kernel to be used in computations.- Parameters:
kernelType- the KernelType to set
-
setPolyDegree
public void setPolyDegree(double polyDegree) Sets the degree of the polynomial kernel, if used- Parameters:
polyDegree- the degree of the polynomial kernel to set
-
setPolyConst
public void setPolyConst(double polyConst) Sets the constant of the polynomial kernel, if used- Parameters:
polyConst- the constant of the polynomial kernel to set
-
getRows
Returns the rows used in the test.- Specified by:
getRowsin interfaceRowsSettable- Returns:
- The rows used in the test.
-
setRows
Allows the user to set which rows are used in the test. Otherwise, all rows are used, except those with missing values.- Specified by:
setRowsin interfaceRowsSettable- Parameters:
rows- The rows to use for the test. Can be null.
-