Learning a CLG
One of the main features of this library is the possibility to learn a CLG.
- More precisely what can be learned is :
The dependency graph of a CLG
The parameters of a CLG: the mu and sigma of each variable, the coefficients of the arcs
Learning the graph
To learn the graph of a CLG (ie the dependence between variables) we use the PC algorithm of Spirtes et al. [SGS00], as written in Colombo and Maathuis [CM14].
The independence test used is based on Simionato and Vandin [SV23].
- class pyagrum.clg.learning.CLGLearner(data=None, *, n_sample=15, fwer_delta=0.05, filename=None)
Learns a CLG from data, the independence tests bounding the FWER (Family-Wise Error Rate) with Rademacher averages.
- Parameters:
data (
str|DataFrame|None)n_sample (
int)fwer_delta (
float)filename (
str|DataFrame|None)
Scientific notes
CLGLearner learns a pyagrum.clg.CLG from a database of continuous variables: the structure with the PC algorithm,
whose independence tests bound the family-wise error rate (FWER) with Rademacher averages
[1][2], then the parameters by least squares.
The adjacency search is the one of the original PC algorithm [3], as written in Algorithms 3.1 and 3.2 of [4]: starting from the complete graph, for \(\ell = 0, 1, \dots\), each ordered pair \((X, Y)\) of adjacent variables is tested given the subsets of size \(\ell\) of the other current neighbours of \(X\); the edge is removed at the first independence found, the subset being kept as separating set. The variables are taken in the order of the columns of the data.
The independence test. For \(X\), \(Y\) and a set \(Z\), \(x\) and \(y\) are the residuals of
the least-squares regressions (with intercept) of \(X\) and \(Y\) on \(Z\) (the raw values if \(Z\) is
empty), centred over the \(K\) records. The statistic is the r-centered statistic of [2]
(Eq. 12), \(\bar r = \frac{1}{K}\sum_i r_i\) with \(r_i = x_i y_i / \max(|x_i|, |y_i|)^2 \in [-1, 1]\), of
expectation 0 when \(X\) and \(Y\) are independent (Theorem 9); \(X \perp Y \mid Z\) is accepted when
\(|\bar r| \leq D\), a bound on the deviation of all the statistics at once. The family \(\mathcal{F}\) holds
the \(L(L-1)\,2^{L-3}\) possible tests (\(L\) variables); with \(n\) (n_sample, 15) vectors
\(\sigma_j\) of \(K\) random signs, the Monte-Carlo empirical Rademacher average and the bound of Theorem 3.1
of [5] are
with \(\lambda = \ln(4/\delta)\) (\(\delta\) = fwer_delta, 0.05), \(z = \max(|a|, |b|) = 1\) and
\(c = b - a = 2\) for the range \([a, b] = [-1, 1]\) of the terms. The bound holds for all the tests at once
with probability at least \(1 - \delta\): the FWER of the independence tests is at most \(\delta\).
Orientation. The v-structures are found from the separating sets, then the rules R1 to R3 of [6] are applied. A pyAgrum heuristic orients what remains: one undirected edge \(X - Y\) is oriented \(X \to Y\) when the empirical standard deviation of \(X\) is at most that of \(Y\), then the rules are applied again, until every edge is oriented. This follows the increasing marginal variances, which often agree with the causal order in simulated linear models but depend on the units of the variables [7].
Parameters. Each variable is regressed on its parents by ordinary least squares: the intercept gives mu, the
slopes the arc coefficients, and sigma is the standard deviation of the residuals (divided by \(K\): maximum
likelihood); a root gets the mean and standard deviation of its values. fitParameters does the same on a given
structure.
Implementation limit. The skeleton may depend on the order of the columns, as the neighbourhoods change during a level (the order-independent PC-stable variant of [4] is not used). All the statistics are computed before the first test, with up to two regressions each: the cost grows as \(L^2 2^L\), which limits the learning to a few variables. The guarantee is paid in power: \(D\) decreases as \(1/\sqrt{K}\), so that a weak dependence needs many records (with six variables and five arcs of coefficients between 0.8 and 2, all the arcs are found from about 10000 records).
Methods
This function is the first step of PC-algo: Adjacency Search. |
|
This function is an advanced version of PC-algo. |
|
Compute the terms of the statistic of the independence test of X and Y given Z, stored in |
|
Find the Markov Boundary of variable T with FWER lower than Delta. |
|
Find the Parent-Children of variable T with FWER lower than Delta. |
|
This function is the second part of the Step1 of PC algorithm. |
|
This function is the fourth step of PC-algo. |
|
This function is used to estimate the parameters of the CLG model. |
|
In this function, we fit the parameters of the CLG model. |
|
Find all the possible combinations of X, Y and Z. |
|
Generator that iterates on all all the subsets of S (from the smallest to the biggest). |
|
Compute the terms of the r-centered statistic of X and Y given Z, stored in |
|
First use PC algorithm to learn the skeleton of the CLG model. |
|
Use n-MCERA to get supremum deviation. |
|
Test the independence of X and Y given Z: the confidence interval of the statistic, of half-width the supremum deviation, must contain 0. |
|
This function is the third step of PC-algo. |
Diego Colombo and Marloes H. Maathuis. Order-independent constraint-based causal structure learning. Journal of Machine Learning Research, 15(116):3921–3962, 2014. URL: https://jmlr.org/papers/v15/colombo14a.html.
Dario Simionato and Fabio Vandin. Bounding the family-wise error rate in local causal discovery using Rademacher averages. In Machine Learning and Knowledge Discovery in Databases (ECML PKDD 2022), Part V, volume 13717 of Lecture Notes in Computer Science, 255–271. Springer, 2023. URL: https://link.springer.com/chapter/10.1007/978-3-031-26419-1_16, doi:10.1007/978-3-031-26419-1_16.
Peter Spirtes, Clark Glymour, and Richard Scheines. Causation, Prediction, and Search. Adaptive Computation and Machine Learning. MIT Press, second edition, 2000. URL: https://direct.mit.edu/books/book/2057/Causation-Prediction-and-Search, doi:10.7551/mitpress/1754.001.0001.