dodiscover.InterventionalContextBuilder#

class dodiscover.InterventionalContextBuilder[source]#

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

The InterventionalContextBuilder is meant solely to build Context objects that work with observational + interventional datasets.

The context builder provides a way to capture assumptions, domain knowledge, and data. This should NOT be instantiated directly. One should instead use dodiscover.make_context() to build a Context data structure.

Notes

The number of distributions and/or interventional targets must be set in order to build the Context object here.

Methods

build()

Build the Context object.

edges([include, exclude])

Set edge constraints to apply in discovery.

excluded_edges(exclude)

Set exclusion edge constraints to apply in discovery.

included_edges(include)

Set inclusion edge constraints to apply in discovery.

init_graph(graph)

Set the partial graph to start with.

intervention_targets(targets)

Set known intervention targets of the data.

latent_variables([latents])

Set latent variables.

num_distributions(num_distribs)

Set the number of data distributions we are expected to have access to.

obs_distribution(has_obs_distrib)

Whether or not we have access to the observational distribution.

observed_variables([observed])

Set observed variables.

state_variable(name, var)

Add a state variable.

state_variables(state_variables)

Set the state variables to use in discovery.

variables([observed, latents, data])

Set variable-list information to utilize in discovery.

build()[source]#

Build the Context object.

Returns:
contextContext

The populated Context object.

edges(include=None, exclude=None)#

Set edge constraints to apply in discovery.

Parameters:
includedOptional[NetworkxGraph]

Edges that should be included in the resultant graph

excludedOptional[NetworkxGraph]

Edges that must be excluded in the resultant graph

Returns:
selfContextBuilder

The builder instance

excluded_edges(exclude)#

Set exclusion edge constraints to apply in discovery.

Parameters:
excludedOptional[NetworkxGraph]

Edges that should be excluded in the resultant graph

Returns:
selfContextBuilder

The builder instance

included_edges(include)#

Set inclusion edge constraints to apply in discovery.

Parameters:
includedOptional[NetworkxGraph]

Edges that should be included in the resultant graph

Returns:
selfContextBuilder

The builder instance

init_graph(graph)#

Set the partial graph to start with.

Parameters:
graphGraph

The new graph instance.

Returns:
selfContextBuilder

The builder instance

intervention_targets(targets)[source]#

Set known intervention targets of the data.

Will also automatically infer the F-nodes that will be present in the graph. For more information on F-nodes see pywhy-graphs.

Parameters:
interventionsList of tuple

A list of tuples of nodes that are known intervention targets. Assumes that the order of the interventions marked are those of the passed in the data.

If intervention targets are unknown, then this is not necessary.

latent_variables(latents=None)#

Set latent variables.

Parameters:
latentsOptional[Set[Column]]

Set of latent “unobserved” variables, by default None. If neither latents, nor variables is set, then it is presumed that variables consists of the columns of data and latents is the empty set.

num_distributions(num_distribs)[source]#

Set the number of data distributions we are expected to have access to.

Note this must include observational too if observational is assumed present. To assume that we do not have access to observational data, use the InterventionalContextBuilder.obs_distribution() to turn off that assumption.

Parameters:
num_distribsint

Number of distributions we will have access to. Will set the number of distributions to be num_distribs + 1 if _obs_distribution is True (default).

obs_distribution(has_obs_distrib)[source]#

Whether or not we have access to the observational distribution.

By default, this is True and assumed to be the first distribution.

observed_variables(observed=None)#

Set observed variables.

Parameters:
observedOptional[Set[Column]]

Set of observed variables, by default None. If neither latents, nor variables is set, then it is presumed that variables consists of the columns of data and latents is the empty set.

state_variable(name, var)#

Add a state variable.

Called by an algorithm to persist data objects that are used in intermediate steps.

Parameters:
namestr

The name of the state variable.

varany

Any state variable.

state_variables(state_variables)#

Set the state variables to use in discovery.

Parameters:
state_variablesDict[str, Any]

The state variables to use in discovery.

Returns:
selfContextBuilder

The builder instance

variables(observed=None, latents=None, data=None)#

Set variable-list information to utilize in discovery.

Parameters:
observedOptional[Set[Column]]

Set of observed variables, by default None. If neither latents, nor variables is set, then it is presumed that variables consists of the columns of data and latents is the empty set.

latentsOptional[Set[Column]]

Set of latent “unobserved” variables, by default None. If neither latents, nor variables is set, then it is presumed that variables consists of the columns of data and latents is the empty set.

dataOptional[pd.DataFrame]

the data to use for variable inference.

Returns:
selfContextBuilder

The builder instance

Examples using dodiscover.InterventionalContextBuilder#

Causal discovery with interventional data - Sachs dataset

Causal discovery with interventional data - Sachs dataset

Causal discovery with interventional data - Sachs dataset