dowhy.utils package

Submodules

dowhy.utils.api module

dowhy.utils.api.parse_state(state)[source]

dowhy.utils.cli_helpers module

dowhy.utils.cli_helpers.query_yes_no(question, default=True)[source]

Ask a yes/no question via standard input and return the answer.

Source: https://stackoverflow.com/questions/3041986/apt-command-line-interface-like-yes-no-input

If invalid input is given, the user will be asked until they actually give valid input. Args:

question(str): A question that is presented to the user. default(bool|None): The default value when enter is pressed with no value. When None, there is no default value and the query will loop.

Returns:

A bool indicating whether user has entered yes or no.

Side Effects:

Blocks program execution until valid input(y/n) is given.

dowhy.utils.dgp module

class dowhy.utils.dgp.DataGeneratingProcess(**kwargs)[source]

Bases: object

Base class for implementation of data generating process.

Subclasses implement functions that create various data generating processes. All data generating processes are in the package “dowhy.utils.dgps”.

DEFAULT_PERCENTILE = 0.9
convert_to_binary(data, deterministic=False)[source]
generate_data()[source]
generation_process()[source]

dowhy.utils.graph_operations module

dowhy.utils.graph_operations.adjacency_matrix_to_adjacency_list(adjacency_matrix, labels=None)[source]

Convert the adjacency matrix of a graph to an adjacency list.

Parameters
  • adjacency_matrix – A numpy array representing the graph adjacency matrix.

  • labels – List of labels.

Returns

Adjacency list as a dictionary.

dowhy.utils.graph_operations.adjacency_matrix_to_graph(adjacency_matrix, labels=None)[source]

Convert a given graph adjacency matrix to DOT format.

Parameters
  • adjacency_matrix – A numpy array representing the graph adjacency matrix.

  • labels – List of labels.

Returns

Graph in DOT format.

dowhy.utils.graph_operations.find_ancestor(node_set, node_names, adjacency_matrix, node2idx, idx2node)[source]

Finds ancestors of a given set of nodes in a given graph.

Parameters
  • node_set – Set of nodes whos ancestors must be obtained.

  • node_names – Name of all nodes in the graph.

  • adjacency_matrix – Graph adjacency matrix.

  • node2idx – A dictionary mapping node names to their row or column index in the adjacency matrix.

  • idx2node – A dictionary mapping the row or column indices in the adjacency matrix to the corresponding node names.

Returns

OrderedSet containing ancestors of all nodes in the node_set.

dowhy.utils.graph_operations.find_c_components(adjacency_matrix, node_set, idx2node)[source]

Obtain C-components in a graph.

Parameters
  • adjacency_matrix – Graph adjacency matrix.

  • node_set – Set of nodes whos ancestors must be obtained.

  • idx2node – A dictionary mapping the row or column indices in the adjacency matrix to the corresponding node names.

Returns

List of C-components in the graph.

dowhy.utils.graph_operations.induced_graph(node_set, adjacency_matrix, node2idx)[source]

To obtain the induced graph corresponding to a subset of nodes.

Parameters
  • node_set – Set of nodes whos ancestors must be obtained.

  • adjacency_matrix – Graph adjacency matrix.

  • node2idx – A dictionary mapping node names to their row or column index in the adjacency matrix.

Returns

Numpy array representing the adjacency matrix of the induced graph.

dowhy.utils.graph_operations.str_to_dot(string)[source]

Converts input string from graphviz library to valid DOT graph format.

Parameters

string – Graph in DOT format.

Returns

DOT string converted to a suitable format for the DoWhy library.

dowhy.utils.ordered_set module

class dowhy.utils.ordered_set.OrderedSet(elements=None)[source]

Bases: object

Python class for ordered set. Code taken from https://github.com/buyalsky/ordered-hash-set/tree/5198b23e01faeac3f5398ab2c08cb013d14b3702.

add(element)[source]

Function to add an element to do set if it does not exit.

Parameters

element – element to be added.

difference(other_set)[source]

Function to remove elements in self._set which are also present in other_set.

Parameters

other_set – The set to obtain difference with. Can be a list, set or OrderedSet.

Returns

New OrderedSet representing the difference of elements in the self._set and other_set.

get_all()[source]

Function to return list of all elements in the set.

Returns

List of all items in the set.

intersection(other_set)[source]

Function to compute the intersection of self._set and other_set.

Parameters

other_set – The set to obtain intersection with. Can be a list, set or OrderedSet.

Returns

New OrderedSet representing the set with elements common to the OrderedSet object and other_set.

is_empty()[source]

Function to determine if the set is empty or not.

Returns

True if the set is empty, False otherwise.

union(other_set)[source]

Function to compute the union of self._set and other_set.

Parameters

other_set – The set to obtain union with. Can be a list, set or OrderedSet.

Returns

New OrderedSet representing the set with elements from the OrderedSet object and other_set.

dowhy.utils.propensity_score module

dowhy.utils.propensity_score.binarize_discrete(data, covariates, variable_types)[source]
dowhy.utils.propensity_score.binary_treatment_model(data, covariates, treatment, variable_types)[source]
dowhy.utils.propensity_score.categorical_treatment_model(data, covariates, treatment, variable_types)[source]
dowhy.utils.propensity_score.continuous_treatment_model(data, covariates, treatment, variable_types)[source]
dowhy.utils.propensity_score.discrete_to_integer(discrete)[source]
dowhy.utils.propensity_score.get_type_string(variables, variable_types)[source]
dowhy.utils.propensity_score.propensity_of_treatment_score(data, covariates, treatment, model='logistic', variable_types=None)[source]
dowhy.utils.propensity_score.state_propensity_score(data, covariates, treatments, variable_types=None)[source]

Module contents