Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional api/causal estimators #746

Merged
merged 56 commits into from Dec 3, 2022
Merged

Conversation

andresmor-ms
Copy link
Collaborator

@andresmor-ms andresmor-ms commented Nov 4, 2022

  • Introduce fit() method to estimators.
  • Refactor constructors to avoid using *args and **kwargs and have more explicit parameters.
  • Refactor refuters and other parts of the code to use fit() and modify arguments to estimate_effect()

@andresmor-ms andresmor-ms marked this pull request as ready for review November 9, 2022 14:08
@andresmor-ms
Copy link
Collaborator Author

test advanced

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

7 similar comments
@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests succeeded! ✅

1 similar comment
@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests succeeded! ✅

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests failed! ❌

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

5 similar comments
@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Launching advanced tests 🚀

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests succeeded! ✅

5 similar comments
@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests succeeded! ✅

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests succeeded! ✅

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests succeeded! ✅

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests succeeded! ✅

@github-actions
Copy link

github-actions bot commented Nov 9, 2022

Advanced tests succeeded! ✅

@petergtz petergtz added the enhancement New feature or request label Nov 10, 2022
Copy link
Member

@amit-sharma amit-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andresmor-ms for this comprehensive refactor. I've added inline comments.

docs/source/example_notebooks/dowhy_functional_api.ipynb Outdated Show resolved Hide resolved
dowhy/causal_estimator.py Outdated Show resolved Hide resolved
dowhy/causal_estimator.py Outdated Show resolved Hide resolved
dowhy/causal_estimator.py Show resolved Hide resolved
dowhy/causal_estimator.py Show resolved Hide resolved
dowhy/causal_estimator.py Outdated Show resolved Hide resolved
dowhy/causal_refuters/bootstrap_refuter.py Outdated Show resolved Hide resolved
dowhy/causal_estimator.py Outdated Show resolved Hide resolved
dowhy/causal_refuters/add_unobserved_common_cause.py Outdated Show resolved Hide resolved
dowhy/causal_refuters/data_subset_refuter.py Outdated Show resolved Hide resolved
bloebp and others added 13 commits November 28, 2022 10:02
Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
This avoids a future deprecation warning.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Related to issue #689

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
@andresmor-ms andresmor-ms force-pushed the functional_api/causal_estimators branch from e9a193c to eb7a763 Compare November 28, 2022 16:02
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>
@andresmor-ms andresmor-ms force-pushed the functional_api/causal_estimators branch from 28578ac to 972b071 Compare November 28, 2022 21:47
Copy link
Member

@amit-sharma amit-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciate all these changes @andresmor-ms
I've added a few minor suggestions, but otherwise looks good to me. Happy to merge once you address them.
Nice that this PR also fixes the reason for the main branch failing. thanks for doing that.

Signed-off-by: Andres Morales <andresmor@microsoft.com>
@andresmor-ms andresmor-ms force-pushed the functional_api/causal_estimators branch from cbda5ca to 0b52e75 Compare November 29, 2022 17:28
Signed-off-by: Andres Morales <andresmor@microsoft.com>
Copy link
Member

@amit-sharma amit-sharma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now. Merging.

@amit-sharma amit-sharma merged commit affe095 into main Dec 3, 2022
moberst pushed a commit to moberst/dowhy that referenced this pull request Dec 16, 2022
* Initial refactor

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* fix placebo treatment refuter randint call (py-why#702)

Signed-off-by: Andres Morales <andresmor@microsoft.com>

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Adding ProductRegressor to gcm auto assignment

This model simply takes the product of the inputs.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Make conditional independence test based on regression less flaky

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add workflow to mark and close stale issues

Signed-off-by: Peter Goetz <pego@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Mark econml, pydot, and pygraphviz as extras (py-why#701)

* mark econml, pydot, and pygraphviz as extras

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* restore dep order

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Change mechanics of Docker image build and usage

- Introduce a GH Action to build Docker image for docs generation every time the Dockerfile is changed
- Trigger docs generation when a new Docker image was built
- Minor fix in Dockerfile to avoid outdated apt database

Signed-off-by: Peter Goetz <pego@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix GH Actions workflow docs trigger

This needs to point to the correct title.

Signed-off-by: Peter Goetz <pego@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add an option for auto assignment in distribution change attribution

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Binary bool features now remain binary in one hot encoding for ANMs in gcm

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Import dowhy.causal_estimators.econml locally (py-why#713)

This imports it within the function where it's used. It removes the hard dependency on EconML and only requires it when using sensitivity_non_parametric_partial_r2.

Signed-off-by: Peter Goetz <pego@amazon.com>

Signed-off-by: Peter Goetz <pego@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Adding causal-learn as (required) dependency

The gcm module will heavily rely on the independence tests in the causal-learn package, i.e., it cannot be optional.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add econml, pydot extras to Documentation Build (py-why#714)

* add econml, pydot extras to docs build

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* add econml, pydot extras to other build tasks

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* update nightly install

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Replace HSCI and KCI with causal-learn package functions

The causal-learn package provides more sophisticated implementations of the kernel independence tests. Instead of reimplementing it, we utilize the existing functions from causal-learn instead.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add pytest markers for "focused" and "notebook" (py-why#716)

add pytest markers for notebook, focused to remove runtime warnings

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Make a gcm unit test for drawing from an interventional distribution less flaky (py-why#715)

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix docs-on-demand Issues (py-why#718)

* fix issues with docs-on-demand GH Actions script

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* update image name

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* restore jupyter notebook from main

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* remove accidentally added file

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix avoid retrain estimator on causal_model API

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add independence tests as parameter to distribution change

This removes the option to change the mechanism change test directly. As it turned out, changing the independence test is the more common case.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Make unit test on intervention less strict

To avoid flaky tests.

Signed-off-by: Peter Goetz <pego@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix issue with identifying boolean values of dataframes in is_categorical

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Restore some key tests into the regular CI pipeline (py-why#725)

* restore some key notebook tests

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* remove advanced marks from unit tests

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* remove advanced mark from test_validation.py

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* apply formatting

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* update test durations, restore some test notebooks

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* bump the test splits

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

* restore main notebook tests, take a more piecemeal approach

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Re-introduce include_simulated_confounder as method

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add constants name

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Use a different github action for notifying discord (py-why#731)

use a different github action for notifying discord

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Set seed on data generation for deterministic test

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Uncomment notebook examples for coverage

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Check random_state type on placebo_treatment_refuter Fix py-why#719

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* introduce fit() method for causal estimators

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix refuters after estimator refactor

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix refutation issues

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix estimator issues

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Restore Notebook Tests in Regular CI (py-why#728)

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Upgrade xgboost (py-why#739)

upgrade xgboost

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>

Signed-off-by: Chris Trevino <darthtrevino@gmail.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Remove bibtex from GCM introduction

This is covered in docs/source/cite.rst.

Signed-off-by: Peter Goetz <pego@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add 'Typical usage' section in GCM introduction

Signed-off-by: Peter Goetz <pego@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix issue with categorical inputs to gcm ProductRegressor

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Use concat instead of append for pandas in distribution change

This avoids a future deprecation warning.

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Remove unnecessary double underscores in gcm module

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Rename gcm bootstrap training to fit_and_compute

Related to issue py-why#689

Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Clean output of notebook

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* format + small fix on tests

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add docs

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add docs to fit()

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add types to constructors

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Apply format

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Use protocol for econml and causalml, PR comments

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* update docs for estimator classes

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add optional data param for estimate_effect

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Update docs

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Fix merge

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Format code

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Address PR comments

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Add docs + fix placebo_refuter

Signed-off-by: Andres Morales <andresmor@microsoft.com>

* Update docs

Signed-off-by: Andres Morales <andresmor@microsoft.com>

Signed-off-by: Andres Morales <andresmor@microsoft.com>
Signed-off-by: Patrick Bloebaum <bloebp@amazon.com>
Signed-off-by: Peter Goetz <pego@amazon.com>
Signed-off-by: Chris Trevino <darthtrevino@gmail.com>
Co-authored-by: Patrick Bloebaum <bloebp@amazon.com>
Co-authored-by: Peter Goetz <pego@amazon.com>
Co-authored-by: Chris Trevino <darthtrevino@users.noreply.github.com>
Co-authored-by: Peter Götz <pego@amazon.de>
Co-authored-by: Patrick Blöbaum <51325689+bloebp@users.noreply.github.com>
@bloebp bloebp deleted the functional_api/causal_estimators branch December 12, 2023 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

5 participants