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.
- edges(include=None, exclude=None)#
Set edge constraints to apply in discovery.
- Parameters:
- included
Optional
[NetworkxGraph
] Edges that should be included in the resultant graph
- excluded
Optional
[NetworkxGraph
] Edges that must be excluded in the resultant graph
- included
- Returns:
- self
ContextBuilder
The builder instance
- self
- excluded_edges(exclude)#
Set exclusion edge constraints to apply in discovery.
- Parameters:
- excluded
Optional
[NetworkxGraph
] Edges that should be excluded in the resultant graph
- excluded
- Returns:
- self
ContextBuilder
The builder instance
- self
- included_edges(include)#
Set inclusion edge constraints to apply in discovery.
- Parameters:
- included
Optional
[NetworkxGraph
] Edges that should be included in the resultant graph
- included
- Returns:
- self
ContextBuilder
The builder instance
- self
- init_graph(graph)#
Set the partial graph to start with.
- Parameters:
- graph
Graph
The new graph instance.
- graph
- Returns:
- self
ContextBuilder
The builder instance
- self
- 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:
- interventions
List
oftuple
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.
- interventions
- latent_variables(latents=None)#
Set latent variables.
- Parameters:
- latents
Optional
[Set
[Column
]] Set of latent “unobserved” variables, by default None. If neither
latents
, norvariables
is set, then it is presumed thatvariables
consists of the columns ofdata
andlatents
is the empty set.
- latents
- 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_distribs
int
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).
- num_distribs
- 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:
- observed
Optional
[Set
[Column
]] Set of observed variables, by default None. If neither
latents
, norvariables
is set, then it is presumed thatvariables
consists of the columns ofdata
andlatents
is the empty set.
- observed
- state_variable(name, var)#
Add a state variable.
Called by an algorithm to persist data objects that are used in intermediate steps.
- state_variables(state_variables)#
Set the state variables to use in discovery.
- Parameters:
- state_variables
Dict
[str
,Any
] The state variables to use in discovery.
- state_variables
- Returns:
- self
ContextBuilder
The builder instance
- self
- variables(observed=None, latents=None, data=None)#
Set variable-list information to utilize in discovery.
- Parameters:
- observed
Optional
[Set
[Column
]] Set of observed variables, by default None. If neither
latents
, norvariables
is set, then it is presumed thatvariables
consists of the columns ofdata
andlatents
is the empty set.- latents
Optional
[Set
[Column
]] Set of latent “unobserved” variables, by default None. If neither
latents
, norvariables
is set, then it is presumed thatvariables
consists of the columns ofdata
andlatents
is the empty set.- data
Optional
[pd.DataFrame
] the data to use for variable inference.
- observed
- Returns:
- self
ContextBuilder
The builder instance
- self
Examples using dodiscover.InterventionalContextBuilder
#
Causal discovery with interventional data - Sachs dataset