{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/natural-counterfactuals-with-necessary","title":"Natural Counterfactuals With Necessary Backtracking","arxiv_id":"2402.01607","date":"2024-02-02","proceeding":null,"authors":["Guang-Yuan Hao","Jiji Zhang","Biwei Huang","Hao Wang","Kun Zhang"],"abstract":"Counterfactual reasoning is pivotal in human cognition and especially important for providing explanations and making decisions. While Judea Pearl's influential approach is theoretically elegant, its generation of a counterfactual scenario often requires too much deviation from the observed scenarios to be feasible, as we show using simple examples. To mitigate this difficulty, we propose a framework of \\emph{natural counterfactuals} and a method for generating counterfactuals that are more feasible with respect to the actual data distribution. Our methodology incorporates a certain amount of backtracking when needed, allowing changes in causally preceding variables to minimize deviations from realistic scenarios. Specifically, we introduce a novel optimization framework that permits but also controls the extent of backtracking with a naturalness criterion. Empirical experiments demonstrate the effectiveness of our method. The code is available at https://github.com/GuangyuanHao/natural_counterfactuals.","url_abs":"https://arxiv.org/abs/2402.01607v3","url_pdf":"https://arxiv.org/pdf/2402.01607v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"natural-counterfactuals-with-necessary","repo_url":"https://github.com/GuangyuanHao/natural_counterfactuals","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"pytorch","reach":{"status":"ok"}}],"tasks":[{"task_slug":"counterfactual-reasoning","task_name":"Counterfactual Reasoning"},{"task_slug":null,"task_name":"counterfactual"}],"methods":[{"method_slug":"counterfactuals","method_name":"Counterfactuals"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"syntology_url":null,"atlas_url":"https://app.syntology.ai/?focus=2402.01607","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2402.01607"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/GuangyuanHao/natural_counterfactuals","reach":{"status":"ok"}}],"summary":{"ran":8,"ran_honours":2,"unverified":4},"by_repo_kind":{"official":{"samples":14,"ran":10,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":14,"samples":[{"code_sha256_prefix":"efd38eeab140dae7","entry":"beta_anneal","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/utils.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"efd38eeab140dae7"}},{"code_sha256_prefix":"26510d6c3ca752bb","entry":"const_max","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/dmol.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/dmol.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"26510d6c3ca752bb"}},{"code_sha256_prefix":"83dd101ccaa7dc31","entry":"const_min","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/dmol.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/dmol.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"83dd101ccaa7dc31"}},{"code_sha256_prefix":"b9020d1327a25f72","entry":"gaussian_kl","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/vae.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/vae.py","link_basis":"plan_row","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b9020d1327a25f72"}},{"code_sha256_prefix":"6d65b56cd5ec3730","entry":"gaussian_kl","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/simple_vae.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/simple_vae.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6d65b56cd5ec3730"}},{"code_sha256_prefix":"a4d7c4fb6e70eb53","entry":"get_attr_max_min","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/datasets.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/datasets.py","link_basis":"plan_row","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"a4d7c4fb6e70eb53"}},{"code_sha256_prefix":"b6459bf0f6db3122","entry":"get_t_i_max_min","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/datasets.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/datasets.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"b6459bf0f6db3122"}},{"code_sha256_prefix":"9893d00262df0805","entry":"linear_warmup","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/utils.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/utils.py","link_basis":"harvester_set","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"9893d00262df0805"}},{"code_sha256_prefix":"ccff70918d85924a","entry":"log_prob_from_logits","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/dmol.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/dmol.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"ccff70918d85924a"}},{"code_sha256_prefix":"46b8ef0bfcd48ee3","entry":"normalize","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/utils.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/utils.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"46b8ef0bfcd48ee3"}},{"code_sha256_prefix":"2c0340928cef8be8","entry":"add_arguments","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/hps.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/hps.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"2c0340928cef8be8"}},{"code_sha256_prefix":"6717f15242b1a22b","entry":"sample_gaussian","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/vae.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/vae.py","link_basis":"plan_row","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"6717f15242b1a22b"}},{"code_sha256_prefix":"0c3673aea1cda139","entry":"sample_gaussian","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/simple_vae.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/simple_vae.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"0c3673aea1cda139"}},{"code_sha256_prefix":"0dbf927c0938e54f","entry":"setup_hparams","repo":"GuangyuanHao/natural_counterfactuals","repo_kind":"official","path":"src-2o/hps.py","file_url":"https://github.com/GuangyuanHao/natural_counterfactuals/blob/HEAD/src-2o/hps.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"NONE","inline_ok":false,"mcp_get_code":{"code_sha256":"0dbf927c0938e54f"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}