Skip to content

Commit 21a37a9

Browse files
committed
Removing autolguon as optional dependency
The autogluon models can still be used with DoWhy, but it is not listed as an optional dependency anymore to reduce the number of restrictions on other packages. Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
1 parent c0c49ed commit 21a37a9

12 files changed

+264
-1652
lines changed

docs/source/example_notebooks/dowhy_causal_discovery_example.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"for method, lib in functions.items():\n",
128128
" obj = lib()\n",
129129
" output = obj.predict(data_mpg)\n",
130-
" adj_matrix = nx.to_numpy_matrix(output)\n",
130+
" adj_matrix = nx.to_numpy_array(output)\n",
131131
" adj_matrix = np.asarray(adj_matrix)\n",
132132
" graph_dot = make_graph(adj_matrix, labels)\n",
133133
" graphs[method] = graph_dot\n",
@@ -252,7 +252,7 @@
252252
"outputs": [],
253253
"source": [
254254
"labels = [f'{col}' for i, col in enumerate(data_sachs.columns)]\n",
255-
"adj_matrix = nx.to_numpy_matrix(graph_sachs)\n",
255+
"adj_matrix = nx.to_numpy_array(graph_sachs)\n",
256256
"adj_matrix = np.asarray(adj_matrix)\n",
257257
"graph_dot = make_graph(adj_matrix, labels)\n",
258258
"display(graph_dot)"
@@ -293,7 +293,7 @@
293293
" obj = lib()\n",
294294
" output = obj.predict(data_sachs)\n",
295295
" graphs_nx[method] = output\n",
296-
" adj_matrix = nx.to_numpy_matrix(output)\n",
296+
" adj_matrix = nx.to_numpy_array(output)\n",
297297
" adj_matrix = np.asarray(adj_matrix)\n",
298298
" graph_dot = make_graph(adj_matrix, labels)\n",
299299
" graphs[method] = graph_dot\n",

docs/source/example_notebooks/dowhy_optimize_backdoor_example.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"nodes = []\n",
5151
"for i in graph.nodes:\n",
5252
" nodes.append(str(i))\n",
53-
"adjacency_matrix = np.asarray(nx.to_numpy_matrix(graph))\n",
53+
"adjacency_matrix = np.asarray(nx.to_numpy_array(graph))\n",
5454
"graph_dot = graph_operations.adjacency_matrix_to_graph(adjacency_matrix, nodes)\n",
5555
"graph_dot = graph_operations.str_to_dot(graph_dot.source)\n",
5656
"print(\"Graph Generated.\")\n",

docs/source/example_notebooks/gcm_supply_chain_dist_change.ipynb

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
},
9090
"outputs": [],
9191
"source": [
92-
"data.groupby(['week']).mean()[['received']].plot(kind='bar', title='average received', legend=False); "
92+
"data.groupby(['week']).mean(numeric_only=True)[['received']].plot(kind='bar', title='average received', legend=False);"
9393
]
9494
},
9595
{
@@ -130,7 +130,7 @@
130130
"metadata": {},
131131
"outputs": [],
132132
"source": [
133-
"data.groupby(['week']).mean().plot(kind='bar', title='average', legend=True);"
133+
"data.groupby(['week']).mean(numeric_only=True).plot(kind='bar', title='average', legend=True);"
134134
]
135135
},
136136
{
@@ -305,7 +305,7 @@
305305
"data_week2 = buying_data(2, 1, demand_mean=4)\n",
306306
"data_week2['week'] = 'w2'\n",
307307
"\n",
308-
"data = data_week1.append(data_week2, ignore_index=True)\n",
308+
"data = pd.concat([data_week1, data_week2], ignore_index=True)\n",
309309
"# write data to a csv file\n",
310310
"# data.to_csv('supply_chain_week_over_week.csv', index=False)"
311311
]

dowhy/causal_graph.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ def get_adjacency_matrix(self, *args, **kwargs):
443443
Get adjacency matrix from the networkx graph
444444
445445
"""
446-
return nx.convert_matrix.to_numpy_matrix(self._graph, *args, **kwargs)
446+
return nx.convert_matrix.to_numpy_array(self._graph, *args, **kwargs)
447447

448448
def check_valid_frontdoor_set(
449449
self, nodes1, nodes2, candidate_nodes, frontdoor_paths=None, new_graph=None, dseparation_algo="default"

dowhy/causal_identifier/backdoor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_backdoor_vars(self):
101101

102102
# Get adjacency list
103103
adjlist = adjacency_matrix_to_adjacency_list(
104-
nx.to_numpy_matrix(undirected_graph), labels=list(undirected_graph.nodes)
104+
nx.to_numpy_array(undirected_graph), labels=list(undirected_graph.nodes)
105105
)
106106
path_dict = {}
107107
backdoor_sets = [] # Put in backdoor sets format

dowhy/gcm/_noise.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -143,11 +143,11 @@ def noise_samples_of_ancestors(
143143
continue
144144

145145
if is_root_node(causal_model.graph, node):
146-
noise = causal_model.causal_mechanism(node).draw_samples(num_samples)
146+
noise = causal_model.causal_mechanism(node).draw_samples(num_samples).reshape(-1)
147147
drawn_noise_samples[node] = noise
148148
drawn_samples[node] = noise
149149
else:
150-
noise = causal_model.causal_mechanism(node).draw_noise_samples(num_samples)
150+
noise = causal_model.causal_mechanism(node).draw_noise_samples(num_samples).reshape(-1)
151151
drawn_noise_samples[node] = noise
152152
drawn_samples[node] = causal_model.causal_mechanism(node).evaluate(
153153
_parent_samples_of(node, causal_model, drawn_samples), noise

dowhy/gcm/fitting_sampling.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ def draw_samples(causal_model: ProbabilisticCausalModel, num_samples: int) -> pd
9292
causal_mechanism = causal_model.causal_mechanism(node)
9393

9494
if is_root_node(causal_model.graph, node):
95-
drawn_samples[node] = causal_mechanism.draw_samples(num_samples)
95+
drawn_samples[node] = causal_mechanism.draw_samples(num_samples).reshape(-1)
9696
else:
97-
drawn_samples[node] = causal_mechanism.draw_samples(_parent_samples_of(node, causal_model, drawn_samples))
97+
drawn_samples[node] = causal_mechanism.draw_samples(
98+
_parent_samples_of(node, causal_model, drawn_samples)
99+
).reshape(-1)
98100

99101
return drawn_samples
100102

dowhy/gcm/uncertainty.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
import numpy as np
7-
from numpy.dual import det
7+
from numpy.linalg import det
88
from scipy.special import digamma
99
from scipy.stats import entropy
1010
from sklearn.neighbors import NearestNeighbors

dowhy/gcm/validation.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
the future.
55
"""
66
from enum import Enum, auto
7-
from typing import Any, Callable, Dict, Optional, Set, Tuple, Union
7+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
88

99
import networkx as nx
1010
import numpy as np
@@ -59,7 +59,7 @@ def refute_causal_structure(
5959
if parents and non_descendants:
6060
# test local Markov condition, null hypothesis: conditional independence
6161
lmc_p_value = conditional_independence_test(
62-
data[node].values, data[non_descendants].values, data[parents].values
62+
data[node].to_numpy(), data[non_descendants].to_numpy(), data[parents].to_numpy()
6363
)
6464
lmc_test_result = dict(p_value=lmc_p_value)
6565
all_p_values.append(lmc_p_value)
@@ -160,8 +160,8 @@ def refute_invertible_model(
160160
)
161161

162162

163-
def _get_non_descendants(causal_graph: DirectedGraph, node: Any, exclude_parents: bool = False) -> Set[Any]:
163+
def _get_non_descendants(causal_graph: DirectedGraph, node: Any, exclude_parents: bool = False) -> List[Any]:
164164
nodes_to_exclude = nx.descendants(causal_graph, node).union({node})
165165
if exclude_parents:
166166
nodes_to_exclude = nodes_to_exclude.union(causal_graph.predecessors(node))
167-
return set(causal_graph.nodes).difference(nodes_to_exclude)
167+
return list(set(causal_graph.nodes).difference(nodes_to_exclude))

dowhy/graph_learners/cdt.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def learn_graph(self, labels=None):
2727
graph = self._method.predict(self._data)
2828

2929
# Get adjacency matrix
30-
self._adjacency_matrix = nx.to_numpy_matrix(graph)
30+
self._adjacency_matrix = nx.to_numpy_array(graph)
3131
self._adjacency_matrix = np.asarray(self._adjacency_matrix)
3232

3333
# If labels not provided

0 commit comments

Comments
 (0)