Skip to content

Commit

Permalink
addressing some early comments by Amit
Browse files Browse the repository at this point in the history
  • Loading branch information
andresmor-ms committed Sep 16, 2022
1 parent 765d097 commit dd4b31d
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 122 deletions.
Expand Up @@ -57,7 +57,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -84,7 +84,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -149,7 +149,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -165,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -174,13 +174,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 5,
"metadata": {},
"outputs": [
{
"ename": "TypeError",
"evalue": "__init__() got an unexpected keyword argument 'method_name'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb Cell 13\u001b[0m in \u001b[0;36m<cell line: 1>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=0'>1</a>\u001b[0m ident_eff \u001b[39m=\u001b[39m BackdoorIdentifier(\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=1'>2</a>\u001b[0m estimand_type\u001b[39m=\u001b[39;49mCausalIdentifierEstimandType\u001b[39m.\u001b[39;49mNONPARAMETRIC_ATE,\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=2'>3</a>\u001b[0m method_name\u001b[39m=\u001b[39;49mBackdoorAdjustmentMethod\u001b[39m.\u001b[39;49mBACKDOOR_EFFICIENT,\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3'>4</a>\u001b[0m )\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=4'>5</a>\u001b[0m \u001b[39mprint\u001b[39m(\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=5'>6</a>\u001b[0m ident_eff\u001b[39m.\u001b[39midentify_effect(\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=6'>7</a>\u001b[0m graph\u001b[39m=\u001b[39mG, treatment_name\u001b[39m=\u001b[39mtreatment_name, outcome_name\u001b[39m=\u001b[39moutcome_name, conditional_node_names\u001b[39m=\u001b[39mconditional_node_names\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=7'>8</a>\u001b[0m )\n\u001b[1;32m <a href='vscode-notebook-cell://wsl%2Bubuntu/home/andresmor/Projects/dowhy/docs/source/example_notebooks/dowhy_efficient_backdoor_example.ipynb#X65sdnNjb2RlLXJlbW90ZQ%3D%3D?line=8'>9</a>\u001b[0m )\n",
"\u001b[0;31mTypeError\u001b[0m: __init__() got an unexpected keyword argument 'method_name'"
]
}
],
"source": [
"ident_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_EFFICIENT,\n",
")\n",
"print(\n",
" ident_eff.identify_effect(\n",
Expand Down Expand Up @@ -211,7 +223,7 @@
"source": [
"ident_minimal_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_MIN_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_MIN_EFFICIENT,\n",
")\n",
"print(\n",
" ident_minimal_eff.identify_effect(\n",
Expand All @@ -235,7 +247,7 @@
"source": [
"ident_mincost_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_MINCOST_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_MINCOST_EFFICIENT,\n",
")\n",
"print(\n",
" ident_mincost_eff.identify_effect(\n",
Expand Down Expand Up @@ -314,7 +326,7 @@
"source": [
"ident_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_EFFICIENT,\n",
")\n",
"try:\n",
" results_eff = ident_eff.identify_effect(graph=G, treatment_name=treatment_name, outcome_name=outcome_name)\n",
Expand All @@ -330,7 +342,7 @@
"source": [
"ident_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_MIN_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_MIN_EFFICIENT,\n",
")\n",
"print(\n",
" ident_minimal_eff.identify_effect(\n",
Expand All @@ -349,7 +361,7 @@
"source": [
"ident_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_MINCOST_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_MINCOST_EFFICIENT,\n",
")\n",
"print(\n",
" ident_mincost_eff.identify_effect(\n",
Expand Down Expand Up @@ -404,7 +416,7 @@
"source": [
"ident_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_EFFICIENT,\n",
")\n",
"try:\n",
" results_eff = ident_eff.identify_effect(\n",
Expand Down Expand Up @@ -499,7 +511,7 @@
"source": [
"ident_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_MINCOST_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_MINCOST_EFFICIENT,\n",
" costs=costs,\n",
")\n",
"print(\n",
Expand All @@ -524,7 +536,7 @@
"source": [
"ident_eff = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method_name=BackdoorAdjustmentMethod.BACKDOOR_MIN_EFFICIENT,\n",
" backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_MIN_EFFICIENT,\n",
")\n",
"print(\n",
" ident_minimal_eff.identify_effect(\n",
Expand Down
26 changes: 15 additions & 11 deletions docs/source/example_notebooks/functional_api.ipynb
Expand Up @@ -6,8 +6,9 @@
"metadata": {},
"outputs": [],
"source": [
"from dowhy import identify_effect, CausalModel\n",
"from dowhy import CausalModel\n",
"from dowhy.causal_identifier import (\n",
" identify_effect,\n",
" BackdoorIdentifier,\n",
" BackdoorAdjustmentMethod,\n",
" IDIdentifier,\n",
Expand Down Expand Up @@ -61,16 +62,13 @@
"metadata": {},
"outputs": [],
"source": [
"# identify_effect method returns a tuple: identifier (CausalIdentifier instance) and an IdentifiedEstimand|IDExpression instance\n",
"# the identifier is returned for backwards compatibility with old api\n",
"# New functional API\n",
"\n",
"_, identified_estimand = identify_effect(\n",
"identified_estimand = identify_effect(\n",
" graph=graph,\n",
" treatment=treatment_name,\n",
" outcome=outcome_name,\n",
" method=BackdoorIdentifier,\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method=BackdoorIdentifier(estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE),\n",
")\n",
"print(identified_estimand)"
]
Expand Down Expand Up @@ -100,7 +98,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Advanced Configuration check \n",
"# Another way of executing the identify effect by directly calling the object\n",
"\n",
"identifier = BackdoorIdentifier(\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE, backdoor_adjustment=BackdoorAdjustmentMethod.BACKDOOR_DEFAULT\n",
Expand All @@ -122,12 +120,11 @@
"outputs": [],
"source": [
"# New functional API (IDIdentifier)\n",
"_, identified_estimand = identify_effect(\n",
"identified_estimand = identify_effect(\n",
" graph=graph,\n",
" treatment=treatment_name,\n",
" outcome=outcome_name,\n",
" estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE,\n",
" method=IDIdentifier,\n",
" method=IDIdentifier(estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE),\n",
")\n",
"print(identified_estimand)"
]
Expand Down Expand Up @@ -157,7 +154,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Advanced Configuration (IDIdentifier)\n",
"# Another way of executing the identify effect by directly calling the object\n",
"\n",
"identifier = IDIdentifier(estimand_type=CausalIdentifierEstimandType.NONPARAMETRIC_ATE)\n",
"\n",
Expand All @@ -169,6 +166,13 @@
"\n",
"print(identified_estimand)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
2 changes: 1 addition & 1 deletion dowhy/__init__.py
@@ -1,6 +1,6 @@
import logging

from dowhy.causal_model import CausalModel, identify_effect
from dowhy.causal_model import CausalModel

logging.getLogger(__name__).addHandler(logging.NullHandler())

Expand Down
2 changes: 1 addition & 1 deletion dowhy/causal_estimators/two_stage_regression_estimator.py
Expand Up @@ -6,7 +6,7 @@

from dowhy.causal_estimator import CausalEstimate, CausalEstimator
from dowhy.causal_estimators.linear_regression_estimator import LinearRegressionEstimator
from dowhy.causal_identifier.causal_identifier import CausalIdentifierEstimandType
from dowhy.causal_identifier.identify_effect import CausalIdentifierEstimandType
from dowhy.utils.api import parse_state


Expand Down
13 changes: 12 additions & 1 deletion dowhy/causal_identifier/__init__.py
@@ -1,3 +1,14 @@
from dowhy.causal_identifier.backdoor_identifier import BackdoorIdentifier, BackdoorAdjustmentMethod
from dowhy.causal_identifier.causal_identifier import CausalIdentifierEstimandType, IdentifiedEstimand
from dowhy.causal_identifier.identify_effect import CausalIdentifierEstimandType, IdentifiedEstimand
from dowhy.causal_identifier.id_identifier import IDIdentifier
from dowhy.causal_identifier.identify_effect import identify_effect


__all__ = [
"BackdoorIdentifier",
"BackdoorAdjustmentMethod",
"CausalIdentifierEstimandType",
"IdentifiedEstimand",
"IDIdentifier",
"identify_effect",
]
4 changes: 2 additions & 2 deletions dowhy/causal_identifier/backdoor_identifier.py
Expand Up @@ -7,7 +7,7 @@
import sympy.stats as spstats

from dowhy.causal_graph import CausalGraph
from dowhy.causal_identifier.causal_identifier import CausalIdentifierEstimandType, IdentifiedEstimand
from dowhy.causal_identifier.identify_effect import CausalIdentifierEstimandType, IdentifiedEstimand
from dowhy.causal_identifier.efficient_backdoor import EfficientBackdoor
from dowhy.utils.api import parse_state

Expand Down Expand Up @@ -56,7 +56,6 @@ def __init__(
proceed_when_unidentifiable: bool = False,
optimize_backdoor: bool = False,
costs: Optional[List] = None,
**kwargs,
):
self.estimand_type = estimand_type
self.backdoor_adjustment = backdoor_adjustment
Expand All @@ -71,6 +70,7 @@ def identify_effect(
treatment_name: Union[str, List[str]],
outcome_name: Union[str, List[str]],
conditional_node_names: List[str] = None,
**kwargs,
):
"""Main method that returns an identified estimand (if one exists).
Expand Down

0 comments on commit dd4b31d

Please sign in to comment.