API reference#
Everything listed here is public. Modules, functions, methods and attributes
whose names start with an underscore, and names a module does not list in its
__all__, are implementation details and may change without notice. The
data, graphs, scores, searches and metrics the federated methods use are
causalbase’s, and documented in the causalbase API reference.
Stability#
fedcausal follows semantic versioning from 1.0.0: within a major version, the names below keep their signatures and meaning, and code written against one release runs on the next. What may change in a minor release is the exact structure learned when two operators or two fusions score the same up to rounding, since a faster kernel may sum the same terms in another order; such changes are listed in the changelog. Scores of a given structure on given data do not change beyond rounding.
The score objects cache what they compute and are not safe to share between threads; use one per thread, or processes.
Only the transport, fedcausal.flower, needs the federated extra.
Estimators#
Both are importable from fedcausal itself. Hyperparameters go to the
constructor, fit() takes one table per site, and the results end in an
underscore.
|
Learn one causal structure from data held by several sites. |
|
Learn a linear non-Gaussian causal model from continuous data held by several sites. |
FedGES#
The rounds of FedGES, run in one process. fedges.Search names the
searches a site can run ("ges", "xges0", "xges") and
fedges.Refinement how a site refines the fused network ("forward",
"backward", "both").
|
A FedGES participant: it learns from its own data and merges in the global model. |
|
Runs a list of sites, either in this process or spread over worker processes. |
|
A learned structure and its score. |
|
A stopping rule for the rounds. |
Stop once every site rebuilds a model it has built before. |
|
Stop once the sites' mean score no longer improves. |
|
|
Stop once any of criteria would. |
|
Run up to n_rounds rounds and return the last global DAG and the rounds run. |
Return the default rule: no score improvement, or every model repeated. |
Fusion#
Each operator is a class, which carries its settings, and a function of the
same name in lower case. fusion.EdgeBudget names the budgets of
MaxEdges ("mean", "max", "min").
|
Combine several DAGs over the same node set into one consensus DAG. |
|
FusionOperator for |
FusionOperator for the full consensus union (no edge budget). |
|
|
FusionOperator for |
|
FusionOperator for |
|
FusionOperator for |
Skeleton-intersection fusion as a |
|
Union every edge appearing in at least percent percent of the inputs. |
|
Return the full consensus union of dags (Puerta et al. 2021). |
|
Union the highest-frequency edges up to a total-edge budget. |
|
Union every edge appearing in at least limit of the inputs. |
|
Union edges in frequency order, giving no node more than limit parents. |
|
Return the skeleton intersection of dags, oriented by |
|
Return |
|
Return a topological order that the DAGs in dags agree on as much as possible. |
|
Return dag re-expressed as a minimal I-map whose arcs all follow order. |
FedRCD#
The solvers are pure functions of the moment sums each site sends.
lingam.MomentSums and lingam.Cumulants are the types of those
statistics, and lingam.Pruning and lingam.LambdaSelection name the
options of the coefficient estimator.
|
Find the causal order from aggregated cumulants, then estimate the coefficients. |
|
Find the causal order by deflating each site's data, one round per source. |
|
Return the moment sums of x, centred on its own mean. |
|
Merge the blocks' moment sums and return the pooled covariance and cumulants. |
|
A causal order and the coefficient matrix estimated for it. |
Sites from one table#
|
Split a dataset into contiguous row blocks, in original order. |
|
Split a dataset across clients via Dirichlet-distribution draws. |
Transport#
Federation across processes or machines with Flower; Deployment shows how to run it.
|
Run FedGES on Flower's simulation engine and return the final global DAG. |
|
Run FedRCD on Flower's simulation engine and return the result. |
|
Register |
|
Register |
|
Handle one |
|
Run the FedGES rounds over grid and return the final global DAG. |
|
Register |
|
Register |
|
Do this site's part of a FedRCD round, for any method, and reply. |
|
Run a FedRCD method over grid and return the result. |
|
Wrap control scalars (round, converged, num_nodes, ...) in a |
|
Pack dag's edges as a |
|
Rebuild a DAG on num_nodes nodes from a |
|
Pack a site's moment sums into an |
|
Rebuild moment sums from a |
|
Return a short digest of the variable names, in order. |
Return a short digest of data's variable names and numbers of levels, in order. |
|
Resolves the dataset a supernode should work from. |
|
Serve one of several in-memory datasets, indexed by |
|
Load a supernode's own CSV, named by a key in its |
Exceptions#
FedCausalError is causalbase’s CausalBaseError, so one except
catches every error either package raises on purpose, and
ConfigurationError, CycleError and NotFittedError are
causalbase’s too. The errors and the warning of the federated methods are
fedcausal’s own:
The federated loop stopped before it produced any global model. |
|
Clients disagree about the variables they are learning over. |
|
Too few clients returned a usable reply in a federated round. |
|
A fused global model came out far denser than the sites' own models. |