<div class="notebook"> <div class="nb-cell markdown" name="md1"> # Causal reasoning in s(CASP) Meta - level abduction with constraints on possible worlds. The following notebook demonstrates how we can use meta level abduction to hypothesis causal networks which are consistant with our data and our stated constraints. The causal networks that are hypothesised can be either fully instantiated or they may have constraits on variables. This work is inspired by "Completing causal networks by meta-level abduction"-2013, and we use similar ideas and patterns to them. But instead of the SOLAR system for reasoning we employ s(CASP) on SWISH which has improved handling of constraints and abduction and allows litrate notebook programs that run in the browser as a cloud application. We aim to demonstrate how this automatic reasoning mimics human epidimological reasoning in a formal automatic way in contrast to Katsumi et als paper which applies there method to the task of reasoning about biological networks. This demonstation has a number of desirable properties that will be of use to epidemiologysts. </div> <div class="nb-cell program" data-background="true" name="p1"> :- use_module(library(scasp)). % Uncomment to suppress warnings :- style_check(-discontiguous). :- style_check(-singleton). :- set_prolog_flag(scasp_unknown, fail). :- set_prolog_flag(scasp_forall, prev). %This might not work with constraints see manual #abducible causal_world(world1,connected(t2d,parkinsons)). #abducible causal_world(world2,connected(parkinsons,t2d)). false :- causal_world(_,connected(t2d,parkinsons)), causal_world(_,connected(parkinsons,t2d)). precedes(X, Y) :- time(X, T1), time(Y, T2), T1 #< T2. temporal_constraint(World) :- causal_world(WorldN,connected(t2d,parkinsons)), World = connected(t2d,parkinsons), precedes(t2d, parkinsons). temporal_constraint(World) :- causal_world(WorldN,connected(parkinsons,t2d)), World = conected(parkinsons,t2d), precedes(parkinsons, t2d). % If we observe a violation of temporal constraints, that world becomes impossible false :- causal_world(WorldN,World), not temporal_constraint(World). time(t2d, 2010). %replace year by T to abduce constraint on possible world time(parkinsons, 2015). % </div> <div class="nb-cell program" data-background="true" data-below="true" data-singleline="true" name="p2"> % Observed effects observed_effect(genetic_variant, t2d, 0.5). % IV increases t2d by 0.5 units observed_effect(genetic_variant, parkinsons, 0.1). % Total effect on parkinson is 0.1 observed_effect(t2d, parkinsons, 0.2). % Estimated causal effect is 0.2 % Model possible unmeasured pathways unmeasured_pathway_strength(weak, 0.1). unmeasured_pathway_strength(moderate, 0.3). unmeasured_pathway_strength(strong, 0.5). % Calculate what remains of observed effect after accounting for unmeasured pathway remaining_effect(PathwayStrength, RemainingEffect) :- observed_effect(genetic_variant, parkinsons, TotalEffect), unmeasured_pathway_strength(PathwayStrength, Strength), RemainingEffect #= TotalEffect - Strength. % Test if causal conclusion holds under different strengths robust_to_pleiotropy(MinEffect) :- % Check if effect remains meaningful even with strong unmeasured pathway remaining_effect(strong, RemainingEffect), RemainingEffect #> MinEffect. % Test plausibility of unmeasured pathways plausible_unmeasured_pathway(PathwayStrength) :- unmeasured_pathway_strength(PathwayStrength, Strength), % Some criterion for plausibility Strength #< 0.4. % Example threshold </div> <div class="nb-cell query" name="q1"> ? temporal_constraint(Causes). </div> <div class="nb-cell query" name="q4"> ? causal_world(W,Causes), temporal_constraint(Causes). </div> <div class="nb-cell query" name="q6"> ? causal_world(W,Causes). </div> <div class="nb-cell query" name="q3"> scasp(causal_world(W,Causes),[model(M)]), member(causal_world(_,connected(A,B)),M), call(true). </div> <div class="nb-cell html" name="htm1"> We can get the model from the s(CASP) query. Can we then use a meta intrepter to prove a query in that? Would we need to use a pengine call to a scasp program? </div> <div class="nb-cell query" name="q7"> pengine_rpc('https://swish.swi-prolog.org',scasp(e,[]),[src_list([(e),(s:-e),(:- use_module(library(scasp)))])]). </div> <div class="nb-cell markdown" name="md3"> For disjunctive heads, I might be able to do something clever with s(CASP) or pengines but I am not sure. with pengines maybe a;b:-c maybe src_list(a:-c);src_list(b:-c))? </div> <div class="nb-cell markdown" name="md4"> a :- not b. b :- not a. This is related to #abducible so could maybe have differnt things in src list that are abducible? </div> <div class="nb-cell program" data-background="true" data-below="true" name="p3"> a :- not b,c. b :- not a,c. c. d :-a. </div> <div class="nb-cell query" name="q8"> ? a. </div> <div class="nb-cell query" name="q9"> ? c. </div> <div class="nb-cell query" name="q10"> ? d. </div> <div class="nb-cell markdown" name="md5"> With these meta predicates we need to make sure the world is consistant, so we need w. </div> <div class="nb-cell program" data-background="true" data-below="true" name="p4"> caused(X,Y,W):-causal_world(W,connected(X,Y)). caused(X,Y,W):-causal_world(W,connected(X,Z)),caused(Z,Y,W). </div> <div class="nb-cell query" name="q11"> ? caused(X,Y,W). </div> <div class="nb-cell markdown" name="md6"> abducible facts. </div> <div class="nb-cell program" name="p5"> caused(X,X,W):-abd(X,W). #abducible abd(walrus,world1). %in world one walruses can appear. </div> <div class="nb-cell query" name="q12"> ? caused(X,Y,W). </div> <div class="nb-cell markdown" name="md7"> I am not sure why I now get two copies of each answer but I guess the model contains walrus or not with the other answer. I do not think this fact thing makes sense in my idea of the whole world being abduced in one go. </div> <div class="nb-cell markdown" name="md8"> "Namely, an inhibitor is preferred to a trigger. 10 This preference rule is often used in applications, particularly in the biological literature.11" </div> <div class="nb-cell query" name="q5"> robust_to_pleiotropy(E), E is rationalize(-0.41). </div> <div class="nb-cell query" name="q2"> precedes(X,Y). </div> <div class="nb-cell markdown" name="md2"> causes(a,b), can be intrepted as meta-level abuduction for b:-a. As in Completing causal networks by meta-level abduction - Inoue </div> </div>