counterfactuals


Namecounterfactuals JSON
Version 1.0.2 PyPI version JSON
download
home_page
SummaryA solver for Counterfactual Inference.
upload_time2024-02-05 22:14:38
maintainer
docs_urlNone
authorR. Kiesel
requires_python>=3.6, <4
licenseMIT
keywords probabilistic logic programming counterfactual reasoning
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # WhatIf
A solver for counterfactual inference over probabilistic logic programs.

`WhatIf` based on the [aspmc](https://github.com/raki123/aspmc/) library for probabilistic logic programming inference.

Its main functionality is the translation of counterfactual queries to marginal queries. 

For usage on Linux you may install this software as a pip package via
```
pip install counterfactuals
```
Examples for command line usage are available below.

If you have any issues please contact us, or even better create an issue on GitHub.

For academic usage cite 

 * Kiesel, R., Rückschloß, K., & Weitkämper, F. (2023, July). "What if?" in Probabilistic Logic Programming. In Proceedings of the 39th International Conference on Logic Programming.

## Development setup
For developement clone via 
```
git clone git@github.com:raki123/counterfactuals.git
```

We require Python >= 3.6. 

All required modules are listed in `requirements.txt` and can be obtained by running
```
pip install -r requirements.txt
```

To use `WhatIf` as usual but have changes to the code available run
```
pip install -e .
```
in the root directory of this repository.

## Usage

The basic usage is

```
WhatIf [-e .] [-ds .] [-dt .] [-k .] [-v .] [-h] [<INPUT-FILES>]
    --knowlege          -k  COMPILER    set the knowledge compiler to COMPILER:
                                        * sharpsat-td       : uses a compilation version of sharpsat-td (default)
                                        * d4                : uses the (slightly modified) d4 compiler. 
                                        * c2d               : uses the c2d compiler. 
                                        * miniC2D           : uses the miniC2D compiler. 
                                        * pysdd             : uses the PySDD compiler. 
    --evidence          -e  NAME,VALUE  add evidence NAME:
                                        * the evidence is not negated if VALUE is `True`.
                                        * the evidence is negated if VALUE is `False`.
    --intervene         -i  NAME,VALUE  intervene on NAME:
                                        * the intervention is not negated if VALUE is `True`.
                                        * the intervention is negated if VALUE is `False`.
    --query             -q  NAME        query for the probability of NAME.
    --decos             -ds SOLVER      set the solver that computes tree decompositions to SOLVER:
                                        * flow-cutter       : uses flow_cutter_pace17 (default)
    --decot             -dt SECONDS     set the timeout for computing tree decompositions to SECONDS (default: 1)
    --verbosity         -v  VERBOSITY   set the logging level to VERBOSITY:
                                        * debug             : print everything
                                        * info              : print as usual
                                        * result            : only print results, warnings and errors
                                        * warning           : only print warnings and errors
                                        * errors            : only print errors
    --help              -h              print this help and exit
```

### Examples
When using the pip package replace `python main.py` by `WhatIf` to obtain the same result.
#### ASP example:
```
python main.py -q slippery -e sprinkler,True -i sprinkler,False -k sharpsat-td
0.5::u1.
0.7::u2.
0.1::u3.
0.6::u4.
szn_spr_sum :- u1.
sprinkler :- szn_spr_sum, u2.
rain :- szn_spr_sum, u3.
rain :- \+szn_spr_sum, u4.
wet :- rain.
wet :- sprinkler.
slippery :- wet.
```
Reads the sprinkler program from stdin and adds evidence `sprinkler` and intervention `\+sprinkler`.
The query is for `slippery`. 

This results in the output
```
[WARNING] aspmc: Query for atom true was proven true during grounding.
[WARNING] aspmc: Including it has a negative impact on performance.
[INFO] aspmc: Tree Decomposition #bags: 18 unfolded treewidth: 3 #vertices: 20
[INFO] aspmc: Preprocessing disabled
[INFO] aspmc:    Stats Compilation
[INFO] aspmc: ------------------------------------------------------------
[INFO] aspmc: Compilation time:         0.005887508392333984
[INFO] aspmc: Counting time:            0.0001952648162841797
[INFO] aspmc: ------------------------------------------------------------
[INFO] WhatIf:    Results
[INFO] WhatIf: ------------------------------------------------------------
[RESULT] WhatIf: slippery:             0.09999999999999999
```
telling us that the result of the counterfactual query for `slippery` is `0.1`. 

The first two lines are a warning from `aspmc` that tell us that the atom `true` that we included to compute the probability of the evidence may lead to decreased performance. However, we need to include it as its probability is not `1.0` in general. 

The following info lines tell us some stats about the program and the inference:
* it has a treewidth upper bound of 3
* aspmc's preprocessing is disabled
* knowledge compilation took ~0.006 seconds
* counting over the resulting circuit took ~0.0002 seconds


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "counterfactuals",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6, <4",
    "maintainer_email": "",
    "keywords": "probabilistic,logic programming,counterfactual reasoning",
    "author": "R. Kiesel",
    "author_email": "rafael.kiesel@tuwien.ac.at",
    "download_url": "https://files.pythonhosted.org/packages/f8/92/8d16844de046ad4160fe3b3b38287e3c13ccd6e7d48cb30db40f402e2732/counterfactuals-1.0.2.tar.gz",
    "platform": null,
    "description": "# WhatIf\nA solver for counterfactual inference over probabilistic logic programs.\n\n`WhatIf` based on the [aspmc](https://github.com/raki123/aspmc/) library for probabilistic logic programming inference.\n\nIts main functionality is the translation of counterfactual queries to marginal queries. \n\nFor usage on Linux you may install this software as a pip package via\n```\npip install counterfactuals\n```\nExamples for command line usage are available below.\n\nIf you have any issues please contact us, or even better create an issue on GitHub.\n\nFor academic usage cite \n\n * Kiesel, R., R\u00fcckschlo\u00df, K., & Weitk\u00e4mper, F. (2023, July). \"What if?\" in Probabilistic Logic Programming. In Proceedings of the 39th International Conference on Logic Programming.\n\n## Development setup\nFor developement clone via \n```\ngit clone git@github.com:raki123/counterfactuals.git\n```\n\nWe require Python >= 3.6. \n\nAll required modules are listed in `requirements.txt` and can be obtained by running\n```\npip install -r requirements.txt\n```\n\nTo use `WhatIf` as usual but have changes to the code available run\n```\npip install -e .\n```\nin the root directory of this repository.\n\n## Usage\n\nThe basic usage is\n\n```\nWhatIf [-e .] [-ds .] [-dt .] [-k .] [-v .] [-h] [<INPUT-FILES>]\n    --knowlege          -k  COMPILER    set the knowledge compiler to COMPILER:\n                                        * sharpsat-td       : uses a compilation version of sharpsat-td (default)\n                                        * d4                : uses the (slightly modified) d4 compiler. \n                                        * c2d               : uses the c2d compiler. \n                                        * miniC2D           : uses the miniC2D compiler. \n                                        * pysdd             : uses the PySDD compiler. \n    --evidence          -e  NAME,VALUE  add evidence NAME:\n                                        * the evidence is not negated if VALUE is `True`.\n                                        * the evidence is negated if VALUE is `False`.\n    --intervene         -i  NAME,VALUE  intervene on NAME:\n                                        * the intervention is not negated if VALUE is `True`.\n                                        * the intervention is negated if VALUE is `False`.\n    --query             -q  NAME        query for the probability of NAME.\n    --decos             -ds SOLVER      set the solver that computes tree decompositions to SOLVER:\n                                        * flow-cutter       : uses flow_cutter_pace17 (default)\n    --decot             -dt SECONDS     set the timeout for computing tree decompositions to SECONDS (default: 1)\n    --verbosity         -v  VERBOSITY   set the logging level to VERBOSITY:\n                                        * debug             : print everything\n                                        * info              : print as usual\n                                        * result            : only print results, warnings and errors\n                                        * warning           : only print warnings and errors\n                                        * errors            : only print errors\n    --help              -h              print this help and exit\n```\n\n### Examples\nWhen using the pip package replace `python main.py` by `WhatIf` to obtain the same result.\n#### ASP example:\n```\npython main.py -q slippery -e sprinkler,True -i sprinkler,False -k sharpsat-td\n0.5::u1.\n0.7::u2.\n0.1::u3.\n0.6::u4.\nszn_spr_sum :- u1.\nsprinkler :- szn_spr_sum, u2.\nrain :- szn_spr_sum, u3.\nrain :- \\+szn_spr_sum, u4.\nwet :- rain.\nwet :- sprinkler.\nslippery :- wet.\n```\nReads the sprinkler program from stdin and adds evidence `sprinkler` and intervention `\\+sprinkler`.\nThe query is for `slippery`. \n\nThis results in the output\n```\n[WARNING] aspmc: Query for atom true was proven true during grounding.\n[WARNING] aspmc: Including it has a negative impact on performance.\n[INFO] aspmc: Tree Decomposition #bags: 18 unfolded treewidth: 3 #vertices: 20\n[INFO] aspmc: Preprocessing disabled\n[INFO] aspmc:    Stats Compilation\n[INFO] aspmc: ------------------------------------------------------------\n[INFO] aspmc: Compilation time:         0.005887508392333984\n[INFO] aspmc: Counting time:            0.0001952648162841797\n[INFO] aspmc: ------------------------------------------------------------\n[INFO] WhatIf:    Results\n[INFO] WhatIf: ------------------------------------------------------------\n[RESULT] WhatIf: slippery:             0.09999999999999999\n```\ntelling us that the result of the counterfactual query for `slippery` is `0.1`. \n\nThe first two lines are a warning from `aspmc` that tell us that the atom `true` that we included to compute the probability of the evidence may lead to decreased performance. However, we need to include it as its probability is not `1.0` in general. \n\nThe following info lines tell us some stats about the program and the inference:\n* it has a treewidth upper bound of 3\n* aspmc's preprocessing is disabled\n* knowledge compilation took ~0.006 seconds\n* counting over the resulting circuit took ~0.0002 seconds\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A solver for Counterfactual Inference.",
    "version": "1.0.2",
    "project_urls": null,
    "split_keywords": [
        "probabilistic",
        "logic programming",
        "counterfactual reasoning"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2035033d4c1d800041857c7885684d5a485d49492921823f1f309157a6f51232",
                "md5": "13e7ea429ef88f08bf507b5dfed1a26e",
                "sha256": "9c3d410bc57f31440932021c4600a00d2dc112d490072a879ddcffefe1144170"
            },
            "downloads": -1,
            "filename": "counterfactuals-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "13e7ea429ef88f08bf507b5dfed1a26e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6, <4",
            "size": 13041,
            "upload_time": "2024-02-05T22:14:36",
            "upload_time_iso_8601": "2024-02-05T22:14:36.169842Z",
            "url": "https://files.pythonhosted.org/packages/20/35/033d4c1d800041857c7885684d5a485d49492921823f1f309157a6f51232/counterfactuals-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f8928d16844de046ad4160fe3b3b38287e3c13ccd6e7d48cb30db40f402e2732",
                "md5": "3b9c52b830e1f8c16a2e7f3a03e99c6d",
                "sha256": "a694b00f3f0f33d3c06f258c24d37945350dcb2f7e6d97e5428e27f20c442705"
            },
            "downloads": -1,
            "filename": "counterfactuals-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "3b9c52b830e1f8c16a2e7f3a03e99c6d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6, <4",
            "size": 16279,
            "upload_time": "2024-02-05T22:14:38",
            "upload_time_iso_8601": "2024-02-05T22:14:38.222610Z",
            "url": "https://files.pythonhosted.org/packages/f8/92/8d16844de046ad4160fe3b3b38287e3c13ccd6e7d48cb30db40f402e2732/counterfactuals-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-05 22:14:38",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "counterfactuals"
}
        
Elapsed time: 2.92808s