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.

fedges.FedGES([n_rounds, criterion, ess, ...])

Learn one causal structure from data held by several sites.

lingam.FedRCD([method, order, pruning, ...])

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").

fedges.Site(data, *[, criterion, ess, ...])

A FedGES participant: it learns from its own data and merges in the global model.

fedges.SitePool(sites[, n_jobs])

Runs a list of sites, either in this process or spread over worker processes.

fedges.BNModel(dag[, score])

A learned structure and its score.

fedges.Convergence(*args, **kwargs)

A stopping rule for the rounds.

fedges.ModelEquality()

Stop once every site rebuilds a model it has built before.

fedges.ScoreImprovement()

Stop once the sites' mean score no longer improves.

fedges.AnyOf(*criteria)

Stop once any of criteria would.

fedges.run_rounds(learn, merge, fusion, ...)

Run up to n_rounds rounds and return the last global DAG and the rounds run.

fedges.default_convergence()

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").

fusion.FusionOperator(*args, **kwargs)

Combine several DAGs over the same node set into one consensus DAG.

fusion.Consensus(percent)

FusionOperator for consensus() with a stored percentage.

fusion.ConsensusUnion()

FusionOperator for the full consensus union (no edge budget).

fusion.MaxEdges([limit])

FusionOperator for max_edges() with a stored budget.

fusion.MaxFrequency(limit)

FusionOperator for max_frequency() with a stored threshold.

fusion.MaxParents(limit)

FusionOperator for max_parents() with a stored cap.

fusion.Intersection()

Skeleton-intersection fusion as a FusionOperator.

fusion.consensus(dags, percent)

Union every edge appearing in at least percent percent of the inputs.

fusion.consensus_union(dags)

Return the full consensus union of dags (Puerta et al. 2021).

fusion.max_edges(dags[, limit])

Union the highest-frequency edges up to a total-edge budget.

fusion.max_frequency(dags, limit)

Union every edge appearing in at least limit of the inputs.

fusion.max_parents(dags, limit)

Union edges in frequency order, giving no node more than limit parents.

fusion.intersection(dags)

Return the skeleton intersection of dags, oriented by dags[0].

fusion.edge_frequency(transformed)

Return ((parent, child), count) over transformed DAGs, most frequent first.

fusion.alpha_order(dags)

Return a topological order that the DAGs in dags agree on as much as possible.

fusion.beta_to_alpha(dag, order)

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.

lingam.fedrcd(stats, *[, method, order, ...])

Find the causal order from aggregated cumulants, then estimate the coefficients.

lingam.fedrcd_exact(sites, *[, order, ...])

Find the causal order by deflating each site's data, one round per source.

lingam.moment_sums(x[, order])

Return the moment sums of x, centred on its own mean.

lingam.cumulants_from_sums(client_stats)

Merge the blocks' moment sums and return the pooled covariance and cumulants.

lingam.RCDResult(causal_order, coef)

A causal order and the coefficient matrix estimated for it.

Sites from one table#

data.contiguous_split(ds, n_clients)

Split a dataset into contiguous row blocks, in original order.

data.dirichlet_split(ds, n_clients, alpha, seed)

Split a dataset across clients via Dirichlet-distribution draws.

Transport#

Federation across processes or machines with Flower; Deployment shows how to run it.

flower.run_flower_fedges(sites, *[, ...])

Run FedGES on Flower's simulation engine and return the final global DAG.

flower.run_flower_rcd(sites, *[, method, ...])

Run FedRCD on Flower's simulation engine and return the result.

flower.fedges.build_client_app(loader[, ...])

Register handle_train_message() as a ClientApp.

flower.fedges.build_server_app(*, n_clients)

Register run_server_loop() as a ServerApp; takes the same arguments.

flower.fedges.handle_train_message(msg, ...)

Handle one train message, a site's whole part of a round, and reply.

flower.fedges.run_server_loop(grid, *, n_clients)

Run the FedGES rounds over grid and return the final global DAG.

flower.lingam.build_client_app(loader)

Register handle_train_message() as a ClientApp.

flower.lingam.build_server_app(*, n_clients)

Register run_server_loop() as a ServerApp; takes the same arguments.

flower.lingam.handle_train_message(msg, ...)

Do this site's part of a FedRCD round, for any method, and reply.

flower.lingam.run_server_loop(grid, *, n_clients)

Run a FedRCD method over grid and return the result.

flower.control_config(**scalars)

Wrap control scalars (round, converged, num_nodes, ...) in a ConfigRecord.

flower.dag_to_record(dag)

Pack dag's edges as a (2, n_edges) int64 ArrayRecord.

flower.record_to_dag(rec, num_nodes)

Rebuild a DAG on num_nodes nodes from a dag_to_record() record.

flower.sums_to_record(stats)

Pack a site's moment sums into an ArrayRecord.

flower.record_to_sums(rec, n)

Rebuild moment sums from a sums_to_record() record.

flower.names_fingerprint(names)

Return a short digest of the variable names, in order.

flower.schema_fingerprint(data)

Return a short digest of data's variable names and numbers of levels, in order.

flower.PartitionLoader(*args, **kwargs)

Resolves the dataset a supernode should work from.

flower.InMemoryPartitions(partitions)

Serve one of several in-memory datasets, indexed by partition-id.

flower.NodeConfigLoader(dataset_cls[, key])

Load a supernode's own CSV, named by a key in its node_config.

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:

exceptions.ConvergedBeforeFusionError

The federated loop stopped before it produced any global model.

exceptions.SchemaMismatchError

Clients disagree about the variables they are learning over.

exceptions.ClientFailureError

Too few clients returned a usable reply in a federated round.

exceptions.DenseFusionWarning

A fused global model came out far denser than the sites' own models.