Skip to content

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 a modified PC algorithm based on Colombo and Maathuis [CM14].

The independence test used is based on Simionato and Vandin [SV22].

class pyagrum.clg.learning.CLGLearner(filename, , n_sample=15, fwer_delta=0.05)

Section titled “class pyagrum.clg.learning.CLGLearner(filename, , n_sample=15, fwer_delta=0.05)”

Using Rademacher Average to guarantee FWER(Family Wise Error Rate) in independency test. (see “Bounding the Family-Wise Error Rate in Local Causal Discover using Rademacher Averages”, Dario Simionato, Fabio Vandin, 2022)

  • Parameters:
    • filename (str)
    • n_sample (int)
    • fwer_delta (float)

This function is the first step of PC-algo: Adjacency Search. Apply indep_test() to the first step of PC-algo for Adjacency Search.

  • Parameters:
    • order (list[int]) – A particular order of the Nodes.
    • verbose (bool) – Whether to print the process of Adjacency Search.
  • Return type: tuple[dict[int, set[int]], dict[tuple[int, int], set[int]]]
  • Returns:
    • C (dict[int, set[int]]) – The temporary skeleton.
    • sepset (dict[tuple[int, int], set[int]]) – Sepset(which will be used in Step2&3 of PC-Algo).

This function is an advanced version of PC-algo. We use Indep_test_Rademacher() to replace indep_test() in PC-algo. And we orient the undirected edges in the skeleton C by comparing the variances of the two nodes.

  • Parameters:
    • order (list[int]) – A particular order of the Nodes.
    • verbose (bool) – Whether to print the process of the PC algorithm.
  • Returns: C – A directed graph DAG representing the causal structure.
  • Return type: dict[int, set[int]]

Estimate Pearson’s linear correlation(using linear regression when Z is not empty).

  • Return type: None

X : id of the first variable tested.

Y : id of the second variable tested.

Z : The conditioned variable’s id set.

  • type X: int
  • param X:
  • type Y: int
  • param Y:
  • type Z: set[int]
  • param Z:

Find the Markov Boundary of variable T with FWER lower than Delta.

  • Parameters: T (int) – The id of the target variable T.
  • Returns: MB – The Markov Boundary of variable T with FWER lower than Delta.
  • Return type: set[int]

Find the Parent-Children of variable T with FWER lower than Delta.

  • Parameters: T (int) – The id of the target variable T.
  • Returns: The Parent-Children of variable T with FWER lower than Delta.
  • Return type: set[int]

This function is the second part of the Step1 of PC algorithm.

  • Parameters:
    • order (list[int]) – The order of the variables.
    • C (dict[int, set[int]]) – The temporary skeleton.
    • l (int) – The size of the sepset
    • verbose (bool) – Whether to print.
  • Returns: found_edge – True if a new edge is found, False if not.
  • Return type: bool

This function is the fourth step of PC-algo. Orient the remaining undirected edge by comparing variances of two nodes.

  • Parameters:
    • C (dict[int, set[int]]) – The temporary skeleton.
    • verbose (bool) – Whether to print the process of Step4.
  • Return type: tuple[dict[int, set[int]], bool]
  • Returns:
    • C (dict[int, set[int]]) – The final skeleton (of Step4).
    • new_oriented (bool) – Whether there is a new edge oriented in the fourth step.

This function is used to estimate the parameters of the CLG model.

  • Parameters: C (dict[int, set[int]]) – A directed graph DAG representing the causal structure.
  • Return type: tuple[dict[int, float], dict[int, float], dict[tuple[int, int], float]]
  • Returns:
    • id2mu (dict[int, float]) – The estimated mean of each node.
    • id2sigma (dict[int, float]) – The estimated variance of each node.
    • arc2coef (dict[tuple[int, int], float]) – The estimated coefficients of each arc.

In this function, we fit the parameters of the CLG model.

  • Parameters: clg (CLG) – The CLG model to be changed its parameters.
  • Return type: None

Find all the possible combinations of X, Y and Z.

  • Returns: All the possible combinations of X, Y and Z.
  • Return type: Generator[tuple[int, int, set[int]], None, None]
  • Parameters: l (list[int])

Generator that iterates on all all the subsets of S (from the smallest to the biggest).

  • Parameters: S (set[int]) – The set of variables.
  • Return type: Generator[set[int], None, None]

First use PC algorithm to learn the skeleton of the CLG model. Then estimate the parameters of the CLG model. Finally create a CLG model and return it.

  • Returns: learned_clg – The learned CLG model.
  • Return type: CLG

r_XYZ : dict[tuple[frozenset[int], frozenset[int]], list[float]]

Section titled “r_XYZ : dict[tuple[frozenset[int], frozenset[int]], list[float]]”

Use n-MCERA to get supremum deviation.

  • Parameters:
    • n_sample (int) – The MC number n in n-MCERA.
    • fwer_delta (float) – Threshold.
  • Returns: SD – The supremum deviation.
  • Return type: float

Perform a standard statistical test and use Bonferroni correction to correct for multiple hypothesis testing.

  • Parameters:
    • X (int) – The id of the first variable tested.
    • Y (int) – The id of the second variable tested.
    • Z (set[int]) – The conditioned variable’s id set.
  • Returns: True if X and Y are indep given Z, False if not indep.
  • Return type: bool

This function is the third step of PC-algo. Orient as many of the remaining undirected edges as possible by repeatedly application of the three rules.

  • Parameters:
    • C (dict[int, set[int]]) – The temporary skeleton.
    • verbose (bool) – Whether to print the process of this function.
  • Returns: C – The final skeleton (of Step3).
  • Return type: dict[int, set[int]]