XGES#
- class causalbase.search.XGES(criterion='bdeu', ess=1.0, expected_parents=1.0, prior='bernoulli', penalty_discount=1.0, alpha_w=None, max_parents=None, max_t_size=None, required=None, forbidden=None, one_edge_faithfulness=False, extended=True, n_jobs=1)[source]#
Learn a causal structure with Extremely Greedy Equivalence Search.
The search is
xges()(Nazaret and Blei, 2024): the same space, score and operators asGES, interleaved so that it applies an improving Delete whenever there is one, then a Reverse, and only then an Insert; edges added early then do not lock the search into a worse optimum.extended=Truethen forces out each edge in turn and searches again from there. It starts from the empty graph, or from initial_graph infit().- Parameters:
- criterion{“bdeu”, “bic”, “gaussian_bic”, “bge”}, default=”bdeu”
The score: BDeu or BIC over categorical data, or the BIC or BGe of a linear Gaussian model over continuous data.
- essfloat, default=1.0
Equivalent sample size: of the BDeu prior, or of BGe’s prior on the mean. Also the prior of the parameters behind
score()on categorical data.- expected_parentsfloat or None, default=1.0
Expected in-degree under the structure prior, for every criterion; see
FamilyScore.Noneis a uniform prior.- prior{“bernoulli”, “tetrad”}, default=”bernoulli”
The structure prior: the Bernoulli prior of
FamilyScore, or, for BDeu only, Tetrad 7.6.5’s, with expected_parents as Tetrad’s structure prior (seeBDeuScore).- penalty_discountfloat, default=1.0
Multiplier of the penalty of the two BIC criteria; larger values give sparser structures.
- alpha_wfloat or None, default=None
Degrees of freedom of BGe’s Wishart prior, above
n_vars + 1;Noneisn_vars + 2. SeeBGeScore.- max_parents, max_t_size, required, forbidden, one_edge_faithfulness
As in
GES.- extendedbool, default=True
Run the forced deletions after XGES-0.
Falseis XGES-0, several times cheaper.- n_jobsint, default=1
Threads of the score’s compiled kernels; -1 is every thread numba has. The result does not depend on it.
- Attributes:
- dag_DAG
The learned network.
- cpdag_PDAG
Its Markov equivalence class.
- score_float
The score of dag_ under criterion, with the structure prior chosen (with
prior="tetrad", the value Tetrad reports).adjacency_pandas.DataFramepandas.DataFrame: The learned CPDAG as a named adjacency matrix.
- n_features_in_int
Number of variables.
- feature_names_in_ndarray of str
Variable names.
- n_iter_int
Operators applied, those of rejected forced deletions included.
- trace_list of tuple
(seconds, steps, score)at the start, after XGES-0 and after each round of forced deletions that improved the score.
Examples
>>> from causalbase import XGES >>> from causalbase.datasets import load_asia >>> model = XGES().fit(load_asia().data) >>> model.cpdag_ PDAG(num_nodes=8, directed=..., undirected=...)
Methods
fit(X[, y, initial_graph])Learn the structure of X.
get_params([deep])Return the estimator's hyperparameters by name.
score(X[, y])Return the mean log likelihood per row of X under the learned network.
set_params(**params)Set hyperparameters by name and return the estimator.
- property adjacency_#
pandas.DataFrame: The learned CPDAG as a named adjacency matrix.
- fit(X, y=None, initial_graph=None)#
Learn the structure of X.
- Parameters:
- XDiscreteDataset, ContinuousDataset, pandas.DataFrame or array-like
Of shape (n_rows, n_vars). For the discrete criteria every distinct value of a column is a level; for
"gaussian_bic"and"bge"the columns are real-valued.- yNone
Ignored.
- initial_graphDAG or PDAG, optional
Where the search starts, over the columns of X: the graph itself for the searches over graphs and equivalence classes, a topological order of it for the searches over orders, and the first solution of the integer program for
ExactSearchwith a parent limit (the dynamic programming has no starting point). A PDAG stands for a DAG it extends to. By default each estimator’s own start, which its docstring gives.
- Returns:
- self
- Raises:
- ValueError
If X has no rows, initial_graph has another number of nodes, or a hyperparameter is out of range (including
prior="tetrad"with a criterion other than"bdeu").
- get_params(deep=True)#
Return the estimator’s hyperparameters by name.
- score(X, y=None)#
Return the mean log likelihood per row of X under the learned network.
The parameters are learned from the training data: by a BDeu prior of equivalent sample size ess for categorical data, by maximum likelihood for continuous data. Higher is better, so a scikit-learn parameter search can select the hyperparameters on held-out rows.
- Parameters:
- XDiscreteDataset, ContinuousDataset, pandas.DataFrame or array-like
Rows over the training variables, with no level the training data lacks.
- yNone
Ignored.
- Returns:
- float
- Raises:
- ValueError
If X has other variables, or a level the training data lacks.
- set_params(**params)#
Set hyperparameters by name and return the estimator.