Add random_state to AddUnobservedCommonCause for reproducible simulation refutation#1571
Open
immu4989 wants to merge 1 commit into
Open
Add random_state to AddUnobservedCommonCause for reproducible simulation refutation#1571immu4989 wants to merge 1 commit into
immu4989 wants to merge 1 commit into
Conversation
…ion refutation Signed-off-by: Imran Ahamed <immu4989@gmail.com>
42 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of making DoWhy's refutation results reproducible (follow-up to #1556 and #1557; related: #556, #418).
What
The
add_unobserved_common_causerefuter is non-deterministic and can't be seeded. In thedirect-simulationpath,_include_confounders_effectdrawsw_random = stdnorm.rvs(num_rows)with norandom_state, so each run produces a different simulated confounder and a different refutation result. The residuals-basedinclude_simulated_confounderpath has the same issue vianp.random.normal.The class only exposes
shuffle_random_seed, which applies solely to the non-parametric-partial-R2 path — there's no way to make the simulation-based refutation reproducible.Changes
random_stateparameter (intornp.random.RandomState, defaultNone) toAddUnobservedCommonCauseand thread it throughsensitivity_simulation→_simulate_confounders_effect_once→_include_confounders_effect(intostdnorm.rvs), and throughinclude_simulated_confounder→_generate_confounder_from_residuals(into the normal draw).np.random.RandomStateonce and pass the instance through, matching the convention already used byRandomCommonCause.random_state=Nonepreserves the existing (non-deterministic) behavior, so this is backward compatible.outcomes = np.random.rand(len(...))lines were only pre-allocating an array that's immediately overwritten in the loop; replaced withnp.zeros(...)to avoid an unnecessary RNG draw.Usage
Verification
new_effect; different seeds → different; default path unchanged and still non-deterministic.tests/causal_refuters/test_add_unobserved_common_cause.pypass; black/isort clean.