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_contextto build a Context data structure.- Parameters:
- variables
Set Set of observed variables. If neither
latents, norvariablesis set, then it is presumed thatvariablesconsists of the columns ofdataandlatentsis the empty set.- latents
Set Set of latent “unobserved” variables. If neither
latents, norvariablesis set, then it is presumed thatvariablesconsists of the columns ofdataandlatentsis the empty set.- init_graph
Graph The graph to start with.
- included_edges
nx.Graph Included edges without direction.
- excluded_edges
nx.Graph Excluded edges without direction.
- state_variables
Dict Name of intermediate state variables during the learning process.
- intervention_targets
listoftuple List of intervention targets (known, or unknown), which correspond to the nodes in the graph (known), or indices of datasets that contain interventions (unknown).
- variables
- Raises:
ValueErrorvariablesandlatentsif both set, should contain the set of all columns indata.
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 the set of f-nodes.
Get the set of non f-nodes.
get_params([deep])Get parameters for this Context.
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.
- get_params(deep=True)#
Get parameters for this Context.
TODO: can update this when we build a causal-Pipeline similar to sklearn’s Pipeline.
- 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:
- **params
dict Estimator parameters.
- **params
- Returns:
- selfinstance
Learner instance.
- state_variable(name, on_missing='raise')[source]#
Get a state variable.
- Parameters:
- name
str The name of the state variable.
- on_missing{‘raise’, ‘warn’, ‘ignore’}
Behavior if
nameis not in the dictionary of state variables. If ‘raise’ (default) will raise a RuntimeError. If ‘warn’, will raise a UserWarning. If ‘ignore’, will returnNone.
- name
- Returns:
- state_var
Any The state variable.
- state_var