API#

dodiscover:

This is the application programming interface (API) reference for classes (CamelCase names) and functions (underscore_case names) of dodiscover, grouped thematically by analysis stage.

Context for causal discovery#

Rather than just data, in many cases structure learning has additional “context”, in the form of apriori knowledge of the structure, or additional datasets from different environments. All structure learning algorithms in dodiscover pass in a Context object rather than just data. One should use our builder make_context API for construction of the Context class.

See docs for Context and make_context for more information.

make_context([context, create_using])

Create a new ContextBuilder instance.

ContextBuilder()

A builder class for creating observational data Context objects ergonomically.

InterventionalContextBuilder()

A builder class for creating observational+interventional data Context objects.

context.Context(observed_variables, ...[, ...])

Context of assumptions, domain knowledge and data.

Constraint-based structure learning#

LearnSkeleton(ci_estimator[, sep_set, ...])

Learn a skeleton graph from observational data without latent confounding.

LearnSemiMarkovianSkeleton(ci_estimator[, ...])

Learning a skeleton from a semi-markovian causal model.

LearnInterventionSkeleton(ci_estimator, ...)

Learn skeleton using observational and interventional data.

ConditioningSetSelection(value)

Available methods for selecting the conditioning sets when learning a skeleton.

PC(ci_estimator[, alpha, min_cond_set_size, ...])

Peter and Clarke (PC) algorithm for causal discovery.

FCI(ci_estimator[, alpha, ...])

The Fast Causal Inference (FCI) algorithm for causal discovery.

PsiFCI(ci_estimator, cd_estimator[, alpha, ...])

Interventional (Psi) FCI algorithm.

Order-based structure learning#

CAM([alpha, prune, n_splines, ...])

The CAM (Causal Additive Model) algorithm for causal discovery.

SCORE([eta_G, eta_H, alpha, prune, ...])

The SCORE algorithm for causal discovery.

DAS([eta_G, eta_H, alpha, prune, ...])

The DAS (Discovery At Scale) algorithm for causal discovery.

NoGAM([n_crossval, ridge_alpha, ...])

The NoGAM (Not only Gaussian Additive Model) algorithm for causal discovery.

Comparing causal discovery algorithms#

confusion_matrix_networks(true_graph, pred_graph)

Compute the confusion matrix comparing a predicted graph from the true graph.

structure_hamming_dist(true_graph, pred_graph)

Compute structural hamming distance.

toporder_divergence(true_graph, order)

Compute topological ordering divergence.

Typing#

We define some custom types to allow 3rd party packages to work with mypy.

Column

SeparatingSet

NetworkxGraph

Graph protocols#

Graph(*args, **kwargs)

Protocol for graphs to work with dodiscover algorithms.

EquivalenceClass(*args, **kwargs)

Protocol for equivalence class of graphs.

Conditional Testing#

Dodiscover experimentally provides an interface for conditional independence testing and conditional discrepancy testing (also known as k-sample conditional independence testing).

Conditional Independence Testing#

Testing for conditional independence among variables is a core part of many causal inference procedures, such as constraint-based structure learning.

BaseConditionalIndependenceTest()

Abstract class for any conditional independence test.

Oracle(graph[, included_nodes])

Oracle conditional independence testing.

KernelCITest([kernel_x, kernel_y, kernel_z, ...])

Methods

GSquareCITest([data_type, levels])

Methods

FisherZCITest([correlation_matrix])

Methods

ClassifierCITest(clf[, metric, bootstrap, ...])

Methods

CMITest([k, transform, n_jobs, ...])

Conditional mutual information independence test.

ClassifierCMITest(clf[, metric, bootstrap, ...])

Methods

CategoricalCITest([lambda_])

Methods

Conditional k-sample testing#

Testing for conditional discrepancy among variables is a core part of many causal inference procedures, such as constraint-based structure learning.

BaseConditionalDiscrepancyTest()

Abstract class for any conditional discrepancy test.

KernelCDTest([distance_metric, metric, l2, ...])

Kernel conditional discrepancy test among conditional distributions.

BregmanCDTest([metric, distance_metric, ...])

Bregman divergence conditional discrepancy test.

Utilities#

Testing for conditional discrepancy among variables is a core part of many causal inference procedures, such as constraint-based structure learning.

compute_kernel(X[, Y, metric, ...])

Compute a kernel matrix and corresponding width.

corrent_matrix(data[, metric, kwidth, ...])

Compute the centered correntropy of a matrix.

von_neumann_divergence(A, B)

Compute Von Neumann divergence between two PSD matrices.

f_divergence_score(y_stat_q, y_stat_p)

Compute f-divergence upper bound on KL-divergence.

kl_divergence_score(y_stat_q, y_stat_p, eps)

Compute f-divergence upper bound on KL-divergence.

Other utilities include support for Monte-Carlo testing for conditional independence.

generate_knn_in_subspace(z_arr[, method, k, ...])

Generate kNN in subspace.

restricted_nbr_permutation(nbrs[, random_seed])

Compute a permutation of neighbors with restrictions.