Counterfactual reasoning tutorial#150
Conversation
Adds a tutorial demonstrating counterfactual reasoning on top of PyReason's annotated logic engine, building on the cybersecurity inconsistency tutorial. Three demos: single-edge graph perturbation, mid-chain fact injection, and inconsistency attribution via fact removal. Includes findings about PyReason's monotonicity behavior — bounds can only tighten, so late conflicting writes are silently rejected rather than triggering inconsistency resolution.
ColtonPayne
left a comment
There was a problem hiding this comment.
Nice Updates, this helps me understand what you are doing a lot - small updates to demo 1 requested.
| Each grounding is independent. Removing a graph edge or fact eliminates | ||
| any grounding that depended on it; the others fire normally. This is | ||
| why counterfactual perturbations have such localized effects -- they | ||
| surgically delete specific groundings without touching the rest. |
There was a problem hiding this comment.
Deleting is only one type of pertubation - say something about modifying, adding, or removing specific groundings rather than just deleting them
| web_server patch_confidence [0.0, 0.2] (none) | ||
| ================ ================= ================= ================== | ||
|
|
||
| ``workstation_1`` and ``dev_server`` are unaffected -- their groundings |
There was a problem hiding this comment.
This makes sense, but show the table starting at line 86 with the grounding removed for at_risk(web_server) for an apples-to-apples comparison. Then, list the vulnerable, compromised, and patch_confidence) rules ahead of this table so we can see why these didn't fire.
| workstation_1 patch_confidence [0.0, 0.2] (none) | ||
| ================ ================= ================= ================== | ||
|
|
||
| A single injected fact eliminated three downstream groundings, exactly |
There was a problem hiding this comment.
This demo is good, use the table structure for reference for demo 1. Just add the rule text for the vulnerable, compromised, and patch confidence rule in demo one and reference that here as well.
| the baseline, consistent in the counterfactual. That is a more subtle | ||
| effect than Demos 1 and 2, where the fact change eliminated | ||
| groundings outright. Here the grounding stays; only its consistency | ||
| changes. |
There was a problem hiding this comment.
Nice work on this demo.
Adds a counterfactual reasoning tutorial
New files:
examples/counterfactual_tutorial_ex.pydocs/source/tutorials/counterfactual_tutorial.rstModified:
docs/source/tutorials/index.rst(registers the new tutorial in the toctree)Builds on the cybersecurity inconsistency tutorial. Reuses the same knowledge graph and rule chain, adds a counterfactual harness that runs PyReason twice (baseline + perturbed) and diffs the resulting interpretations.
Three demos:
at_risk(workstation_1):[0.0, 0.0]to break the rule chain partway through.patch_confidencefact fordev_serverand observe whether the rule-triggered conflict resolves cleanly.