dodiscover.context.Context#

class dodiscover.context.Context(observed_variables, latent_variables, state_variables, init_graph, included_edges, excluded_edges, num_distributions=1, obs_distribution=True, intervention_targets=<factory>, symmetric_diff_map=<factory>, sigma_map=<factory>, f_nodes=<factory>, num_domains=1, domain_map=<factory>, s_nodes=<factory>)[source]#

Context of assumptions, domain knowledge and data.

This should NOT be instantiated directly. One should instead use dodiscover.make_context to build a Context data structure.

Parameters:
variablesSet

Set of observed variables. 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.

latentsSet

Set of latent “unobserved” variables. 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.

init_graphGraph

The graph to start with.

included_edgesnx.Graph

Included edges without direction.

excluded_edgesnx.Graph

Excluded edges without direction.

state_variablesDict

Name of intermediate state variables during the learning process.

intervention_targetslist of tuple

List of intervention targets (known, or unknown), which correspond to the nodes in the graph (known), or indices of datasets that contain interventions (unknown).

Raises:
ValueError

variables and latents if both set, should contain the set of all columns in data.

Notes

Context is a data structure for storing assumptions, domain knowledge, priors and other structured contexts alongside the datasets. This class is used in conjunction with a discovery algorithm.

Setting the a priori explicit direction of an edge is not supported yet.

Testing for equality

Currently, testing for equality is done on all attributes that are not graphs. Defining equality among graphs is ill-defined, and as such, we leave testing of the internal graphs to users. Some checks of equality for example can be networkx.algorithms.isomorphism.is_isomorphic() for checking isomorphism among two graphs.

Methods

add_state_variable(name, var)

Add a state variable.

copy()

Create a deepcopy of the context.

get_augmented_nodes()

Get the set of f-nodes.

get_non_augmented_nodes()

Get the set of non f-nodes.

get_params([deep])

Get parameters for this Context.

reverse_sigma_map()

Get the reverse sigma-map.

set_params(**params)

Set the parameters of this estimator.

state_variable(name[, on_missing])

Get a state variable.

__hash__ = None#
add_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.

copy()[source]#

Create a deepcopy of the context.

get_augmented_nodes()[source]#

Get the set of f-nodes.

get_non_augmented_nodes()[source]#

Get the set of non f-nodes.

get_params(deep=True)#

Get parameters for this Context.

TODO: can update this when we build a causal-Pipeline similar to sklearn’s Pipeline.

Parameters:
deepbool, default=True

If True, will return the parameters for this estimator and contained subobjects that are estimators.

Returns:
paramsdict

Parameter names mapped to their values.

reverse_sigma_map()[source]#

Get the reverse sigma-map.

set_params(**params)#

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects. The latter have parameters of the form <component>__<parameter> so that it’s possible to update each component of a nested object.

Parameters:
**paramsdict

Estimator parameters.

Returns:
selfinstance

Learner instance.

state_variable(name, on_missing='raise')[source]#

Get a state variable.

Parameters:
namestr

The name of the state variable.

on_missing{‘raise’, ‘warn’, ‘ignore’}

Behavior if name is not in the dictionary of state variables. If ‘raise’ (default) will raise a RuntimeError. If ‘warn’, will raise a UserWarning. If ‘ignore’, will return None.

Returns:
state_varAny

The state variable.