Asplain¶
Tip
Use the icon in the top right to see the source code for this page.
Predicate Summary ¶
Name | Definition | Type |
---|---|---|
attr/4 |
Defines an attribute for a node or edge. |
|
edge/3 |
Defines an edge in the graph. They represent the causal relationships between nodes, as well as negative relationships (inhibitors). |
|
node/1 |
Defines a node in the graph |
|
_abducible/2 |
Abducible atoms full |
|
_distance/3 |
Distance between the real and hypothetical model. |
|
_query/2 |
Query that should hold in the hypothetical model |
|
_xclingo_direct_cause/4 |
Models the directed edge |
|
_xclingo_direct_inhibitor/4 |
Captures the Inhibitor-Effect relation between a negative literal in the body of a rule and an atom in the head. This is used for linking the Reference and the Contrastive explanation as the inhibitors of an atom that is in one graph will appear in the other graph. |
|
_xclingo_f_atom/2 |
Means that |
|
_abduced/2 |
Uses the concept of abduction to find the hypothetical model |
|
_model/2 |
Atoms that are part of the model |
|
world/1 |
|
Dependency Graph ¶
flowchart LR
node/1(["node/1"])
_f_atom/2 --> node/1
reachable/2 --> node/1
node/1 --> node/1
edge/3(["edge/3"])
edge/3 --> edge/3
_direct_inhibitor/4 --> edge/3
r_edge/3 --> edge/3
_direct_cause/4 --> edge/3
reachable/2 --> edge/3
node/1 --> edge/3
attr/4(["attr/4"])
_rule/2 --> attr/4
edge/3 --> attr/4
reachable/2 --> attr/4
_abduced/2 --> attr/4
attr/4 --> attr/4
_direct_inhibitor/4 --> attr/4
_f_atom/2 --> attr/4
r_edge/3 --> attr/4
_direct_cause/4 --> attr/4
_query/2 --> attr/4
node/1 --> attr/4
world/1(["world/1"])
_abduced/2(["_abduced/2"])
_abducible/2 --> _abduced/2
_model/2(["_model/2"])
_abduced/2 --> _model/2
_relevant/2(["_relevant/2"])
_model/2 --> _relevant/2
_fbody/4(["_fbody/4"])
_relevant/2 --> _fbody/4
_f_atom/2 --> _fbody/4
_sup/4 --> _fbody/4
_abduced/2 --> _fbody/4
_depends/2 --> _fbody/4
_f/4(["_f/4"])
_relevant/2 --> _f/4
_fbody/4 --> _f/4
_f_atom/2(["_f_atom/2"])
_f/4 --> _f_atom/2
_direct_cause/4(["_direct_cause/4"])
_depends/2 --> _direct_cause/4
_f/4 --> _direct_cause/4
_direct_inhibitor/4(["_direct_inhibitor/4"])
_prevents/2 --> _direct_inhibitor/4
_f/4 --> _direct_inhibitor/4
_model_negators/4(["_model_negators/4"])
_constraints/2 --> _model_negators/4
in_both/1(["in_both/1"])
_f_atom/2 --> in_both/1
r_edge/3(["r_edge/3"])
in_both/1 --> r_edge/3
_f_atom/2 --> r_edge/3
_model_negators/4 --> r_edge/3
node/1 --> r_edge/3
reachable/2(["reachable/2"])
_abducible/2(["_abducible/2"])
_distance/3(["_distance/3"])
_query/2(["_query/2"])
_xclingo_f_atom/2(["_xclingo_f_atom/2"])
_xclingo_direct_cause/4(["_xclingo_direct_cause/4"])
_xclingo_direct_inhibitor/4(["_xclingo_direct_inhibitor/4"])
_sup/4(["_sup/4"])
_depends/2(["_depends/2"])
_prevents/2(["_prevents/2"])
_constraints/2(["_constraints/2"])
_rule/2(["_rule/2"])
classDef all fill:#00000000
class __tmp,node/1,edge/3,attr/4,world/1,_abduced/2,_model/2,_relevant/2,_fbody/4,_f/4,_f_atom/2,_direct_cause/4,_direct_inhibitor/4,_model_negators/4,in_both/1,r_edge/3,reachable/2,_abducible/2,_distance/3,_query/2,_xclingo_f_atom/2,_xclingo_direct_cause/4,_xclingo_direct_inhibitor/4,_sup/4,_depends/2,_prevents/2,_constraints/2,_rule/2, all;
classDef out stroke:#52BF54,stroke-width:3px;
class __tmp,node/1,edge/3,attr/4, out;
classDef aux stroke:#848484,stroke-width:0.2px;
class __tmp,world/1,_abduced/2,_model/2,_relevant/2,_fbody/4,_f/4,_f_atom/2,_direct_cause/4,_direct_inhibitor/4,_model_negators/4,in_both/1,r_edge/3,reachable/2,_abducible/2,_distance/3,_query/2,_xclingo_f_atom/2,_xclingo_direct_cause/4,_xclingo_direct_inhibitor/4,_sup/4,_depends/2,_prevents/2,_constraints/2,_rule/2, aux;
classDef in stroke:#9178C6,stroke-width:3px;
class reachable/2,_abducible/2,_distance/3,_query/2,_xclingo_f_atom/2,_xclingo_direct_cause/4,_xclingo_direct_inhibitor/4,_sup/4,_depends/2,_prevents/2,_constraints/2,_rule/2, in;
Encodings ¶
examples/asplain/base.lp
¶
Encoding
Computes the contrastive graphs using abduction. A contrastive graph will compare a reference model with a hypothetical which fulfils a query.
Example Input
The reference model containing only b
_model(real, b).
b
can be removed from the reference model
_abducible(rm,b).
Each atom abduced will be penalized
_distance(Atom, 1, 1) :- _abduced(_, Atom).
The hypothetical model must include a
_query(include,a),
The input program reified to talk about worlds. This is done automatically by the system.
_model(hypothetical,a) :- not _abduced(rm,a); not _model(hypothetical,b).
_model(hypothetical,b) :- not _abduced(rm,b).
The input program reified to talk support. This is done automatically by the system.
_sup(1,World,a,()) :- world(World); not _model(World,b).
_prevents(_sup(1,World,a,()),b) :- _sup(1,World,a,()).
_sup(2,World,b,()) :- world(World).
#include "abduction.lp".
#include "contrastive.lp".
#include "graphs.lp".
#include "reachable.lp".
#show .
#show node(N):node(N), reachable(node,N).
#show edge(N,N',ID):edge(N,N',ID), reachable(edge,ID).
#show attr(T,ID,A,N):attr(T,ID,A,N), reachable(T,ID).
examples/asplain/abduction.lp
¶
Encoding
Finds the hypothetical model using abduction and the distance defined by the user
#defined _abduced/2.
#defined _model/2.
#defined _distance/3.
:- _query(exclude,Atom), _model(hypothetical,Atom).
:- _query(include,Atom), not _model(hypothetical,Atom).
world(real;hypothetical).
{_abduced(X,Atom)} :- _abducible(X,Atom).
Constraints¶
- (C1) No sense to remove something that is not in input
:- not _model(real,Atom), _abduced(rm,Atom).
- (C2) + (C4) No sense to both remove and add something
:- _abduced(add,Atom), _abduced(rm,Atom).
- (C3) No sense to add something that is already in input
:- _model(real,Atom), _abduced(add,Atom).
_model(hypothetical,Atom) :- _abduced(add, Atom).
Distance¶
:~ _distance(N,D,L). [D@L,N]
Default distance
examples/asplain/contrastive.lp
¶
Encoding
Computes the contrastive graph based on the found hypothetical model
TODO
Do we want to mark atoms that are relevant or just provide the full graph?
At the moment we are not marking the atoms that are relevant, we are just providing the full graph.
_relevant(W, Atom) :- _model(W, Atom).
Firable¶
fireable if abduced
_fbody(_abduced, hypothetical, Atom, ()) :- _abduced(add, Atom).
fireable if fact
_fbody(R, W, Atom, Vars) :- _relevant(W, Atom), _sup(R, W, Atom, Vars), not _depends(_sup(R, W, _, _), _).
firable if supported body.
_fbody(R, W, Atom, Vars) :-
_sup(R, W, Atom, Vars),
_f_atom(W, Cause) : _depends(_sup(R, W, Atom, Vars), Cause).
Decides which rule fire each relevant atom in the graph (must be one and only one).
{_f(R, W, Atom, Vars) : _fbody(R, W, Atom, Vars)} :- _relevant(W, Atom).
:- _f(ID1, W, Atom, _), _f(ID2, W, Atom, _), ID1!=ID2.
:- _relevant(W, Atom), not _f_atom(W,Atom).
_f_atom(W, Atom) :- _f(_, W, Atom, _).
Causes and inhibitors¶
Captures positive body for this graph
_direct_cause((R,Vars), W, Effect, Cause) :-
_f(R, W, Effect, Vars),
_depends(_sup(R, W, Effect, Vars), Cause).
Captures negative body for this graph
_direct_inhibitor((R,Vars), W, Effect, Inhibitor) :-
_f(R, W, Effect, Vars),
_prevents(_sup(R, W, Effect, Vars), Inhibitor).
_model_negators(C, Vars, A1, A2) :-
_constraints(_sup_constraint(C, Vars), A1), _constraints(_sup_constraint(C, Vars), A2), A1!=A2.
examples/asplain/graphs.lp
¶
Encoding
Creates the graph based on the causes and inhibitors
Nodes¶
node(A):-_f_atom(W, A).
attr(node,A,origin,W):- _f_atom(W, A).
attr(node,A,abduced,X):- node(A), _abduced(X,A).
attr(node,A,query,X):- node(A), _query(X,A).
Edges¶
edge(Cause,Effect,((Cause,Effect),(RuleID,VARS))):-_direct_cause((RuleID,VARS), W, Effect, Cause).
attr(edge,((Cause,Effect),(RuleID,VARS)),origin,W):-_direct_cause((RuleID,VARS), W, Effect, Cause).
edge(Cause,Effect,((Cause,Effect),(RuleID,VARS))):-_direct_inhibitor((RuleID,VARS), W, Effect, Cause), node(Effect), node(Cause).
attr(edge,((Cause,Effect),(RuleID,VARS)),type,inhibitor):-_direct_inhibitor((RuleID,VARS), W, Effect, Cause), node(Effect), node(Cause).
attr(edge,((Cause,Effect),(RuleID,VARS)),type,cause):- _direct_cause((RuleID,VARS), W, Effect, Cause).
in_both(A) :- _f_atom(real, A), _f_atom(hypothetical, A).
We take those that interact in integrity constraints.
We force one direction only
r_edge(I1, I2, ((I1,I2),(C_Num,Vars))) :-
_model_negators(C_Num, Vars, I1, I2), % We take those that interact in integrity constraints.
not in_both(I1), not in_both(I2),
_f_atom(real,I1), _f_atom(hypothetical,I2), % We force one direction only
node(I1), node(I2).
edge(I1, I2, EID) :- r_edge(I1, I2, EID).
attr(edge, EID, type, reciprocal_inhibitor) :- r_edge(I1, I2, EID).
attr(edge, ((I1,I2),(C_Num,Vars)), rule_id, C_Num) :- edge(I1, I2, ((I1,I2),(C_Num,Vars))), _rule(C_Num, LABEL).
attr(edge, ((I1,I2),(C_Num,Vars)), rule_str, LABEL) :- edge(I1, I2, ((I1,I2),(C_Num,Vars))), _rule(C_Num, LABEL).
attr(edge, ((I1,I2),(C_Num,Vars)), rule_vars, Vars) :- edge(I1, I2, ((I1,I2),(C_Num,Vars))), _rule(C_Num, LABEL).
Glossary ¶
attr(T,N,A,V)
¶
Defines an attribute for a node or edge.
References
70 |
|
70 |
|
47 |
|
48 |
|
49 |
|
55 |
|
59 |
|
60 |
|
71 |
|
73 |
|
74 |
|
75 |
|
edge(N,N',ID)
¶
Defines an edge in the graph. They represent the causal relationships between nodes, as well as negative relationships (inhibitors).
References
69 |
|
69 |
|
54 |
|
58 |
|
70 |
|
73 |
|
74 |
|
75 |
|
node(A)
¶
Defines a node in the graph
References
68 |
|
68 |
|
46 |
|
48 |
|
49 |
|
58 |
|
58 |
|
59 |
|
59 |
|
64 65 66 67 68 |
|
64 65 66 67 68 |
|
_abducible(T,A)
¶
Abducible atoms full
Parameter | Description |
---|---|
T |
type of abduction |
A |
atom that can be abduced |
References
67 |
|
_distance(N,D,L)
¶
Distance between the real and hypothetical model.
Parameter | Description |
---|---|
N |
Identifier for the distance, each identifier will yield one penalization |
D |
Penalization value |
L |
Level of the distance. Higher levels will be prioritized |
References
84 |
|
_query(T,A)
¶
Query that should hold in the hypothetical model
Parameter | Description |
---|---|
T |
type of query |
A |
atom that the user wants to include or exclude |
References
58 |
|
59 |
|
49 |
|
_xclingo_direct_cause(RuleID, World, Effect, Cause)
¶
Models the directed edge Cause -> Effect
that belongs to the graph World
.
References
_xclingo_direct_inhibitor(RuleID, World, Effect, Inhibitor)
¶
Captures the Inhibitor-Effect relation between a negative literal in the body of a rule and an atom in the head. This is used for linking the Reference and the Contrastive explanation as the inhibitors of an atom that is in one graph will appear in the other graph.
References
_xclingo_f_atom(World, Atom)
¶
Means that Atom
is a node in the World
explanation graph.
References
_abduced(T,A)
¶
Uses the concept of abduction to find the hypothetical model
Parameter | Description |
---|---|
T |
type of abduction |
A |
atom that has been abduced |
References
67 |
|
73 |
|
75 |
|
75 |
|
77 |
|
79 |
|
44 |
|
48 |
|
_model(T,A)
¶
Atoms that are part of the model
Parameter | Description |
---|---|
T |
type of model |
A |
atom that is part of the model |
References
58 |
|
59 |
|
73 |
|
77 |
|
79 |
|
38 |
|
world(W)
¶
Parameter | Description |
---|---|
W |
W is a world; either |
References
66 |
|