dodiscover.ContextBuilder#

class dodiscover.ContextBuilder[source]#

A builder class for creating observational data Context objects ergonomically.

The ContextBuilder is meant solely to build Context objects that work with observational 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.

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.

latent_variables([latents])

Set latent variables.

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)[source]#

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)[source]#

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)[source]#

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)[source]#

Set the partial graph to start with.

Parameters:
graphGraph

The new graph instance.

Returns:
selfContextBuilder

The builder instance

latent_variables(latents=None)[source]#

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.

observed_variables(observed=None)[source]#

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)[source]#

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)[source]#

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)[source]#

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.ContextBuilder#

Causal discovery with interventional data - Sachs dataset

Causal discovery with interventional data - Sachs dataset

Causal discovery with interventional data - Sachs dataset