CoGS: Causality Constrained Counterfactual Explanations using goal-directed ASP††thanks: Authors supported by US NSF Grants IIS 1910131, US DoD, and industry grants.
Abstract
Machine learning models are increasingly used in areas such as loan approvals and hiring, yet they often function as black boxes, obscuring their decision-making processes. Transparency is crucial, and individuals need explanations to understand decisions, especially for the ones not desired by the user. Ethical and legal considerations require informing individuals of changes in input attribute values (features) that could lead to a desired outcome for the user. Our work aims to generate counterfactual explanations by considering causal dependencies between features. We present the CoGS (Counterfactual Generation with s(CASP)) framework that utilizes the goal-directed Answer Set Programming system s(CASP) to generate counterfactuals from rule-based machine learning models, specifically the FOLD-SE algorithm. CoGS computes realistic and causally consistent changes to attribute values taking causal dependencies between them into account. It finds a path from an undesired outcome to a desired one using counterfactuals. We present details of the CoGS framework along with its evaluation.
Keywords:
Causal reasoning Counterfactual reasoning Default Logic Goal-directed Answer Set Programming Planning problem.1 Introduction
Predictive models are widely used in automated decision-making processes, such as job-candidate filtering or loan approvals. These models often function as black boxes, making it difficult to understand their internal reasoning for decision making. The decisions made by these models can have significant consequences, leading individuals to seek satisfactory explanations, especially for an unfavorable decision. This desire for transparency is crucial, whether the decision is made by an automated system or humans. Explaining these decisions presents a significant challenge. Additionally, users want to know what changes they must make to flip an undesired (negative) decision into a desired (positive) one.
In this work we follow Wachter et al.’s [19] approach where counterfactuals are employed to explain the reasoning behind a prediction by a machine learning model. Counterfactuals help answer the following question: “What changes should be made to input attributes or features to flip an undesired outcome to a desired one?" Counterfactuals also serve as a good candidate for explaining a prediction. Wachter et al. [19] use statistical techniques, where they examine the proximity of points in the N-dimensional feature space, to find counterfactuals. We present the Counterfactual Generation with s(CASP) (CoGS) framework, which generates counterfactual explanations from rule-based machine learning (RBML) algorithms such as FOLD-SE [20]. Our framework makes two advances compared to Wachter et al.’s work: (i) It computes counterfactuals using RBML algorithms and ASP, rather than statistical techniques, (ii) It takes causal dependencies among features into account when computing these counterfactuals. Another novelty of the CoGS framework is that it further leverages the FOLD-SE algorithm [20] to automatically discover potential dependencies between features that are subsequently approved by a user.
Our approach models various scenarios (or worlds): the current initial state representing negative a outcome and the goal state representing a positive outcome. A state is represented as a set of feature-value pairs. CoGS finds a path from the initial state to the goal state by performing interventions (or transitions), where each intervention corresponds to changing a feature value while taking causal dependencies among features into account. These interventions ensure realistic and achievable changes that will take us from state to . CoGS relies on common-sense reasoning, implemented through answer set programming (ASP) [10], specifically using the goal-directed s(CASP) ASP system [3]. The problem of finding these interventions can be viewed as a planning problem [10], except that unlike the planning problem, the moves (interventions) that take us from one state to another are not mutually independent.
2 Background
2.0.1 Counterfactual Reasoning:
Explanations help us understand decisions and inform actions. Wachter et al. [19] advocated using counterfactual explanations (CFE) to explain individual decisions, offering insights on how to achieve desired outcomes. For instance, a counterfactual explanation for a loan denial might state: If John had good credit, his loan application would be approved. This involves imagining alternate (reasonably plausible) scenarios where the desired outcome is achievable. For a binary classifier given by , we define a set of counterfactual explanations for a factual input as . This set includes all inputs leading to different predictions than the original input under . We utilize the s(CASP) query-driven predicate ASP system [3] for counterfactual reasoning, incorporating causal dependency between features. s(CASP) computes dual rules (section 2.0.1), allowing negated queries and constructing alternate worlds/states that lead to counterfactual explanations while considering causal dependencies.
Causality Considerations: Causality relates to cause-effect relationship among predicates. is the cause of , if [15]. We say that is causally dependent on . For generating realistic counterfactuals, causal dependencies among features must be taken into account. For example, in a loan approval scenario, increasing the credit score to be ‘high’ while still being under increasing debt obligations is unrealistic due to the causal dependencies between debt, and credit score. Ignoring these dependencies could lead to invalid counterfactuals that do not achieve the desired outcome. Therefore, realistic counterfactual explanations must model these causal relationships to account for downstream effects of feature changes.
ASP, s(CASP) and Commonsense Reasoning: Answer Set Programming (ASP) is a paradigm for knowledge representation and reasoning [8, 4, 10], widely used in automating commonsense reasoning. We employ ASP to encode feature knowledge, decision-making rules, and causal rules, enabling the automatic generation of counterfactual explanations using this symbolic knowledge. s(CASP) is a goal-directed ASP system that executes answer set programs in a top-down manner without grounding [3]. Its query-driven nature aids in commonsense and counterfactual reasoning, utilizing proof trees for justification. To incorporate negation-as-failure, s(CASP) adopts program completion, turning “if” rules into “if and only if” rules. For every rule in a s(CASP) program, its corresponding dual rule(s) is computed. Details can be found elsewhere [3].
FOLD-SE: Wang and Gupta [20] developed FOLD-SE, an efficient, explainable rule-based machine learning (RBML) algorithm for classification tasks. FOLD-SE generates default rules—–a stratified normal logic program—–as an explainable model from the given input dataset. Both numerical and categorical features are allowed. The generated rules symbolically represent the machine learning model that will predict a label, given a data record. FOLD-SE can also be used for learning rules capturing causal dependencies among features in a dataset. FOLD-SE maintains scalability and explainability, as it learns a relatively small number of learned rules and literals regardless of dataset size, while retaining good classification accuracy compared to state-of-the-art machine learning methods. In CoGS, FOLD-SE is used to learn causal rules that accurately model feature dependencies and that are subsequently used to generate realistic counterfactual explanations.
The Planning Problem: Planning involves finding a sequence of transitions from an initial state to a goal state while adhering to constraints. In ASP, this problem is encoded in a logic program with rules defining transitions and constraints restricting the allowed transitions [10]. Solutions are represented as a series of transitions through intermediate states. Each state is represented as a set of facts or logical predicates. Solving the planning problem involves searching for a path of transitions that meets the goal conditions within the constraints. CoGS can be thought of as a framework to find a plan—a series of interventions that change feature values—that will take us from the initial state to the final goal state. However, unlike the planning domain, the interventions (moves) are not independent of each other due to causal dependencies among features.
3 Overview
3.1 The Problem
When an individual (represented as a set of features) receives an undesired negative decision (loan denial), they can seek necessary changes to flip it to a positive outcome. CoGS automatically identifies these changes. For example, if John is denied a loan (initial state ), CoGS models the (positive) scenarios (goal set ) where he obtains the loan. Obviously, the (negative) decision in the initial state should not apply to any scenario in the goal set . The query goal ‘?- reject_loan(john)’ should be True in the initial state and False for all goals in the goal set . The problem is to find a series of intervensions, namely, changes to feature values, that will take us from to .
3.2 Solution: CoGS Approach
Inspired by the planning problem, the CoGS approach casts the solution as traversing from an initial state to a goal state, represented as feature-value pairs (e.g., credit score: 600; age: 24). There can be multiple goal states that represents the positive outcome (set of goal states ). The objective is to turn a negative decision (initial state i) into a positive one (goal state g) through necessary changes to feature values, so that the query goal ‘?- not reject_loan(john)’ will succeed for . As mentioned earlier, the CoGS framework involves solving a variant of the planning problem due to the dependence between features.
CoGS models two scenarios: 1) the negative outcome world (e.g., loan denial, initial state ), and 2) the positive outcome world (e.g., loan approval, goal state ) achieved through specific interventions. The initial state and goal state are defined by specific attribute values (e.g., loan approval requires a credit score >=600). CoGS symbolically computes the necessary interventions to find a path to the goal state , representing a flipped decision.
Given an instance where the decision query (e.g., ‘?- reject_loan/1’) succeeds (negative outcome), CoGS finds the state where this query fails (i.e., the decision query ‘?- not reject_loan/1’ succeeds), which then constitutes the goal state . In terms of ASP, the problem of finding interventions can be cast as follows: given a possible world where a query succeeds, compute changes to the feature values (while taking their causal dependencies into account) that will reach a possible world where negation of the query will succeed. Each of the intermediate possible worlds we traverse must be viable worlds with respect to the rules. We use the s(CASP) query-driven predicate ASP system [3] for this purpose. s(CASP) automatically generates dual rules, allowing us to execute negated queries (such as ‘?- not reject_loan/1’) constructively.
CoGS employs two kinds of actions: 1) Direct Actions: directly changing a feature value, and 2) Causal Actions: changing other features to cause the target feature to change, utilizing the causal dependencies between features. These actions guide the individual from the initial state to the goal state through (consistent) intermediate states, suggesting realistic and achievable changes. Unlike CoGS, Wachter et al.’s approach [19] can output non-viable solutions.
3.2.1 Example 1- Using direct actions to reach the counterfactual state:
Consider a loan application scenario. There are 4 feature-domain pairs: 1) Age: {1 year,…, 99 years}, 2) Debt: {, …, }, 3) Bank Balance: {, …, } and 4) Credit Score: {}.
John (31 years, , , ) applies for a loan. The bank’s rule is to deny loans to individuals with a bank balance of less than . Hence, John is denied a loan (negative outcome). To get his loan approved (positive outcome), CoGS suggests the following: Initial state: John (31 years, , 12 months, , ) is denied a loan. Goal state: John (31 years, , 12 months, , ) is approved for a loan. Intervention: Suggest to John to change his bank balance to . As shown in Fig. 1 (top), the direct action of increasing the bank balance to flips the decision. John becomes eligible for the loan, bypassing bank’s rejection criteria.

Example 2- Highlighting the utility of Causal Actions: This example demonstrates the advantages of incorporating causal rules. Consider a scenario where the bank has two rejection rules: 1) Deny loans to individuals with a bank balance of less than , and 2) Deny loans to individuals with a credit score below . John (31 years, , , ) is denied a loan (negative outcome) but wishes to get it approved (positive outcome). Without the knowledge of causal dependencies, the solution will be the following: Initial state: John (31 years, , 12 months, , ) is denied a loan. Goal state: John (31 years, , 12 months, , ) is approved for a loan. Interventions: 1) Change the bank balance to , and 2) the credit score to . However, credit score cannot be changed directly.
To realistically increase the credit score, the bank’s guidelines suggest 1) having no debt. This leads to a causal dependency between debt and credit score. Incorporating this, CoGS provides: Initial state: John (31 years, , 12 months, , ) is denied a loan. Goal state: John (31 years, , 12 months, , ) is approved for a loan. Interventions: 1) John changes his bank balance to , and 2) reduces his debt to $0 to increase his credit score.
As shown in Figure 1 (bottom), by clearing the debt (direct action), John’s credit score increases (causal effect), making him eligible for the loan. Intermediate states, such as John with in debt and John with in debt, are part of the path to the goal state. This example illustrates how using causal dependencies between features allows realistic achievement of desired outcomes.
Hence, we demonstrate how utilizing causal dependencies between features allows us to realistically achieve desired outcomes by making appropriate changes. The challenge now is to accomplish this automatically, i.e.,: (i) identify causal dependencies automatically: we use a rule-based machine learning algorithm (FOLD-SE) for this purpose. (ii) Compute the sequence of necessary interventions automatically: in particular, we want to avoid repeating states, a known issue in the planning domain. Our CoGS approach addresses these challenges. It generates the path from the initial state i to the counterfactual goal state g using the find_path algorithm (Algorithm 1), explained in Section 4.1.
4 Methodology
We next outline the methodology used by CoGS to generate paths from the initial state (negative outcome) to the goal state (positive outcome). Unlike traditional planning problems where actions are typically independent, our approach involves interdependent actions governed by causal rules . This ensures that the effect of one action can influence subsequent actions, making interventions realistic and causally consistent. Note that the CoGS framework uses the FOLD-SE RBML algorithm [20] to automatically compute causal dependency rules. These rules have to be either verified by a human, or commonsense knowledge must be used to verify them automatically. This is important, as RBML algorithms can identify a correlation as a causal dependency. CoGS uses the former approach. The latter is subject of research. We next define specific terms.
Definition 1 (State Space (S))
represents all combinations of feature values. For domains of the features , is a set of possible states , where each state is defined as a tuple of feature values
(1) |
For example state can be : .
Definition 2 (Causally Consistent State Space ())
is a subset of where all causal rules are satisfied. represents a set of causal rules over the features within a state space . Then, (where is the power set of S) is a function that defines the subset of a given state sub-space that satisfy all causal rules in C.
(2) |
(3) |
E.g., if a causal rule states that if is , the credit score should be above 599, then instance is causally consistent, and instance is causally inconsistent.
In a traditional planning problem, allowed actions in a given state are independent, i.e., the result of one action does not influence another. In CoGS, causal actions are interdependent, governed by .
Definition 3 (Decision Consistent State Space ())
is a subset of where all decision rules are satisfied. represents a set of rules that compute some external decision for a given state. is a function that defines the subset of the causally consistent state space that is also consistent with decision rules in :
(4) |
Given and , we define the decision consistent state space as
(5) |
For example, an individual John whose loan has been rejected: s = ( years, , , points), where .
Definition 4 (Initial State ())
is the starting point with an undesired outcome. Initial state is an element of the causally consistent state space
(6) |
For example,
Definition 5 (Actions)
The set of actions includes all possible interventions (actions) that can transition a state from one to another within the state space. Each action is defined as a function that maps to a new state .
(7) |
Actions are divided into: 1) Direct Actions: Directly change the value of a single feature of a state , e.g., Increase bank balance from to . 2) Causal Actions: Change the value of a target feature by altering related features, based on causal dependencies. It results in a causally consistent state with respect to C, e.g., reduce debt to increase the credit score.
Definition 6 (Transition Function)
A transition function maps a causally consistent state to the set of allowable causally consistent states that can be reached in a single step, and is defined as:
models a function that repeatedly takes actions until a causally consistent state is reached. In example 1, suggests changing the bank balance from to :
Definition 7 (Counterfactual Generation (CFG) Problem)
A counterfactual generation (CFG) problem is a 4-tuple where is causally consistent state space, is the decision consistent state space, is the initial state , and is a transition function.
Definition 8 (Goal Set)
The goal set is the set of desired outcomes that do not satisfy the decision rules . For counterfactual , :
(8) |
includes all states in that do not satisfy . For example 1, an example goal state is
Definition 9 (Solution Path)
A solution to the problem with Goal set is a path:
(9) |
For example 1, individuals with less than in their account are ineligible for a loan, thus the state of an ineligible individual might be . The goal set has only one goal state given by . The path from to is {(31 years,$5000,$40000,599 points)(31 years,$5000,$60000,599 points). Here, the path has only 2 states as only changing the bank balance to be is needed to reach the goal state.
4.1 Algorithm
We next describe our algorithm to find the goal states and compute the solution paths. The algorithm makes use of the following functions: (i) not_member: checks if an element is: a) not a member of a list, and b) Given a list of tuples, not a member of any tuple in the list. (ii) drop_inconsistent: given a list of states [] and a set of Causal rules , it drops all the inconsistent states resulting in a list of consistent states with respect to . (iii) get_last: returns the last member of a list. (iv) pop: returns the last member of a list. (v) is_counterfactual: returns True if the input state is a causally consistent counterfactual solution (see supplement for details [2]).
Find Path: Function ‘find_path’ implements the Solution Path of Definition 9. Its purpose is to find a path to the counterfactual state. Algorithm 1 provides the pseudo-code for ‘find_path’, which takes as input an Initial State , a set of Causal Rules , decision rules , and actions . It returns a path to the counterfactual state/goal state for the given as a list ‘visited_states’. Unrealistic states are removed from ‘visited_states’ to obtain a ‘candidate_path’.
Initially, . The function checks if the current state is a counterfactual. If is already a counterfactual, ‘find_path’ returns a list containing . If not, the algorithm moves from to a new causally consistent state using the ‘intervene’ function, updating ‘visited_states’ with . It then checks if is a counterfactual using ‘is_counterfactual’. If True, the algorithm drops all inconsistent states from ‘visited_states’ and returns the ‘candidate_path’ as the path from to . If not, it updates ‘’ to and repeats until reaching a counterfactual/goal state . The algorithm ends when ‘is_counterfactual’ is satisfied, i.e., .
(10) |
Intervene: Function ‘intervene’ implements the transition function from Definition 6. It is called by ‘find_path’ in line 4 of Algorithm 1. The primary purpose of ‘intervene’ is to transition from the current state to the next state, ensuring actions are not repeated and states are not revisited. Its pseudo-code as well as a detailed exploration is available in the supplement.
Make Consistent: The pseudo-code for ‘make_consistent’ is specified in Algorithm 2. It takes as arguments a current State , a list actions_taken, a list visited_states, a set of Causal Rules and a set of actions . Called by ‘intervene’ in line 12 of Algorithm 4, ‘make_consistent’ transitions from the current state to a new, causally consistent state.
4.1.1 Update
Function ‘update’ tracks the list of actions taken and states visited to avoid repeating actions and revisiting states. Its pseudo-code is provided and explored in detail in the supplement.
Discussion: A few points should be highlighted: (i) Certain feature values may be immutable or restricted, such as age cannot decrease or credit score cannot be directly altered. To respect these restrictions, we introduce plausibility constraints. These constraints apply to the actions in our algorithms, ensuring realistic changes to the features. Since they do not add new states but restrict reachable states, they are represented through the set of available actions in Algorithms 1, 4, 2, 5. (ii) Similarly, CoGS has the ability to specify the path length for candidate solutions. Starting with a minimal path length of 1, CoGS can identify solutions requiring only a single change. If no solution exists, CoGS can incrementally increase the path length until a solution is found. This ensures that the generated counterfactuals are both minimal and causally consistent, enhancing their practicality and interpretability. This is achieved via constraints on path length.
4.2 Soundness
Definition 10 (CFG Implementation)
When Algorithm 1 is executed with the inputs: Initial State (Definition 4), States Space (Definition 1), Set of Causal Rules (Definition 2), Set of Decision Rules (Definition 3), and Set of Actions (Definition 5), a CFG problem (Definition 7) with causally consistent state space (Definition 2), Decision consistent state space (Definition 3), Initial State (Definition 4), the transition function (Definition 6) is constructed.
Definition 11 (Candidate path)
Given the counterfactual constructed from a run of algorithm 1, the return value (candidate path) is the resultant list obtained from removing all elements containing states .
Definition 10 maps the input of Algorithm 1 to a CFG problem (Definition 7). Candidate path maps the result of Algorithm 1 to a possible solution (Definition 9) of the corresponding CGF problem. From Theorem 7.1 (proof in supplement [2]), the candidate path (Definition 11) is a solution to the corresponding CFG problem implementation (Definition 10).
5 Experiments
We applied the CoGS methodology to rules generated by the FOLD-SE algorithm (code on GitHub [2]). Our experiments use the German dataset [11], Adult dataset [5], and the Car Evaluation dataset [7]. These are popular datasets found in the UCI Machine Learning repository [1]. The German dataset contains demographic data with labels for credit risk (‘good’ or ‘bad’), with records with the label ‘good’ greatly outnumbering those labeled ‘bad’. The Adult dataset includes demographic information with labels indicating income (‘’ or ‘’). The Car Evaluation dataset provides information on acceptability of a used car being purchased. We relabelled the Car Evaluation dataset to ‘acceptable’ and ‘unacceptable’ in order to generate the counterfactuals.
For the (imbalanced) German dataset, the learned FOLD-SE rules determine ‘good’ credit rating, with the undesired outcome being a ‘good’ rating, since the aim is to identify criteria making someone a credit risk (‘bad’ rating). Additionally, causal rules are also learnt using FOLD-SE and verified (for example, if feature ‘Job’ has value ‘unemployed’, then feature ‘Present employment since’ should have the value ‘unemployed/unskilled-non-resident’). We learn the rules to verify these assumptions on cause-effect dependencies.
By using these rules that identify individuals with a ‘good’ rating, we found a path to the counterfactuals thereby depicting steps to fall from a ‘good’ to a ‘bad’ rating in Table 1. Similarly, we learn the causal rules as well as the rules for the undesired outcome for the Adult dataset (undesired outcome: ‘’). For the Car Evaluation dataset (undesired outcome: ‘unacceptable’), we only learn the rules for the undesired outcome as there are no causal dependencies (FOLD-SE did not generate any either). Table 1 shows a path to the counterfactual goal state for a specific instance for each of these datasets. Note that the execution time for finding the counterfactuals is also reported. While we have only shown specific paths in Table 1, our CoGS methodology can generate all possible paths from an original instance to a counterfactual. Note that each path may represent a set of counterfactuals. This is because numerical features may range over an interval. Thus, CoGS generates 240 sets of counterfactuals for the the German dataset, 112 for the Adult dataset, and 78 for the Car Evaluation dataset (See Table 2 in the supplement [2]).
Dataset | Features | Initial State | Action | Goal State | Time (ms) |
---|---|---|---|---|---|
german | Checking account status | N/A | 3236 | ||
Credit history | no credits taken/all credits paid back duly | N/A | no credits taken/all credits paid back duly | ||
Property | real estate | Direct | car or other | ||
Duration months | 7 | N/A | 7 | ||
Credit amount | 500 | N/A | 500 | ||
Job | unemployed | N/A | unemployed | ||
Present Employment Since | unemployed/unskilled-non-resident | N/A | unemployed/unskilled-non-resident | ||
car evaluation | persons | 4 | N/A | 4 | 1221 |
maint | low | Direct | medium | ||
buying | medium | N/A | medium | ||
safety | medium | N/A | medium |
Dataset | Features | Initial State | Action | Intermediate | Action | Goal State | Time (ms) |
---|---|---|---|---|---|---|---|
adult | Marital_Status | never_married | N/A | never_married | Causal | married_civ_spouse | 1126 |
Capital Gain | $6000 | N/A | N/A | N/A | and | ||
Education_num | N/A | N/A | N/A | ||||
Relationship | unmarried | Direct | husband | N/A | husband | ||
Sex | male | N/A | N/A | N/A | male | ||
Age | 28 | N/A | N/A | N/A | 28 |
6 Related Work and Conclusion
Various methods for generating counterfactual explanations in machine learning have been proposed. Wachter et al. [19] aimed to provide transparency in automated decision-making by suggesting changes individuals could make to achieve desired outcomes. However, they ignored causal dependencies, resulting in unrealistic suggestions. Utsun et al. [18] introduced algorithmic recourse, offering actionable paths to desired outcomes but assuming feature independence, which is often unrealistic. CoGS rectifies this by incorporating causal dependencies. Karimi et al. [12] focused on feature immutability and diverse counterfactuals, ensuring features like gender or age are not altered and maintain model-agnosticism. However, this method also assumes feature independence, limiting realism. Existing approaches include model-specific, optimization-based approaches [17, 16]. White et al. [21] showed how counterfactuals can enhance model performance and explanation accuracy . Karimi et al. [13] further emphasized incorporating causal rules in counterfactual generation for realistic and achievable interventions. However their method did not use the ‘if and only’ property which is vital in incorporating the effects of causal dependence. Bertossi and Reyes [6] rectified this by utilizing Answer Set Programming (ASP) but they relied on grounding, which can disconnect variables from their associations. In contrast, CoGS does not require grounding as it leverages s(CASP) to generate counterfactual explanations, providing a clear path from undesired to desired outcomes.
Eiter et al. [9] proposed a framework for generating contrastive explanations in the context of ASP, focusing on why one particular outcome occurred instead of another. While contrastive explanations identify and compare the assumptions leading to different outcomes, CoGS goes further by incorporating causal dependencies, ensuring that the generated counterfactuals are realistic and achievable.
The main contribution of this paper is the Counterfactual Generation with s(CASP) (CoGS) framework for automatically generating counterfactuals while taking causal dependencies into account to flip a negative outcome to a positive one. CoGS has the ability to find minimal paths by iteratively adjusting the path length. This ensures that explanations are both minimal and causally consistent. CoGS is flexible, generating counterfactuals irrespective of the underlying rule-based machine learning (RBML) algorithm. The causal dependencies can be learned from data using any RBML algorithm, such as FOLD-SE. The goal-directed s(CASP) ASP system plays a crucial role, as it allows us to compute a possible world in which a query Q fails by finding the world in which the query not Q succeeds. CoGS advances the state of the art by combining counterfactual reasoning, causal modeling, and ASP-based planning, offering a robust framework for realistic and actionable counterfactual explanations. Our experimental results show that counterfactuals can be computed for complex models in a reasonable amount of time. Future work will explore computing counterfactuals for image classification tasks, inspired by Padalkar et al [14].
References
- [1] UCI machine learning repository, https://archive.ics.uci.edu/
- [2] Supplement: CoGS: Causality Constrained Counterfactual Explanations using Goal-directed ASP (2024), https://github.com/sopam/Supplementary
- [3] Arias, J., Carro, M., Salazar, E., Marple, K., Gupta, G.: Constraint Answer Set Programming without Grounding. TPLP 18(3-4), 337–354 (2018)
- [4] Baral, C.: Knowledge representation, reasoning and declarative problem solving. Cambridge University Press (2003)
- [5] Becker, B., Kohavi, R.: Adult. UCI Machine Learning Repository (1996), DOI: https://doi.org/10.24432/C5XW20
- [6] Bertossi, L.E., Reyes, G.: Answer-set programs for reasoning about counterfactual interventions and responsibility scores for classification. In: Proc. ILP. LNCS
- [7] Bohanec, M.: Car Evaluation. UCI Machine Learning Repository (1997), DOI: https://doi.org/10.24432/C5JP48
- [8] Brewka, G., Eiter, T., Truszczynski, M.: Answer set programming at a glance. Commun. ACM 54(12), 92–103 (2011)
- [9] Eiter, T., Geibinger, T., Oetsch, J.: Contrastive explanations for answer-set programs. In: Logics in Artificial Intelligence JELIA. pp. 73–89. LNCS (2023)
- [10] Gelfond, M., Kahl, Y.: Knowledge representation, reasoning, and the design of intelligent agents: Answer Set Programming approach. Cambridge Univ. Press (2014)
- [11] Hofmann, H.: Statlog (German Credit Data). UCI Machine Learning Repository (1994), DOI: https://doi.org/10.24432/C5NC77
- [12] Karimi, A., Barthe, G., Balle, B., Valera, I.: Model-agnostic counterfactual explanations for consequential decisions. In: AISTATS. PMLR (2020)
- [13] Karimi, A., Schölkopf, B., Valera, I.: Algorithmic recourse: from counterfactual explanations to interventions. In: Proc. ACM FAccT. pp. 353–362 (2021)
- [14] Padalkar, P., Wang, H., Gupta, G.: NeSyFOLD: A framework for interpretable image classification. In: Proc. AAAI (2024)
- [15] Pearl, J.: Causal inference in statistics: An overview. Statistics Surveys 3(none), 96 – 146 (2009), https://doi.org/10.1214/09-SS057
- [16] Russell, C.: Efficient search for diverse coherent explanations. In: Proc. ACM FAT. p. 20–28 (2019)
- [17] Tolomei, G., Silvestri, F., Haines, A., Lalmas, M.: Interpretable predictions of tree-based ensembles via actionable feature tweaking. In: Proc. ACM SIGKDD
- [18] Ustun, B., Spangher, A., Liu, Y.: Actionable recourse in linear classification. In: FAT. ACM (2019)
- [19] Wachter, S., Mittelstadt, B.D., Russell, C.: Counterfactual explanations without opening the black box: Automated decisions and the GDPR. CoRR
- [20] Wang, H., Gupta, G.: FOLD-SE: an efficient rule-based machine learning algorithm with scalable explainability. In: Proc. PADL 2024. pp. 37–53. Springer LNCS 14512
- [21] White, A., d’Avila Garcez, A.S.: Measurable counterfactual local explanations for any classifier. In: Proc. ECAI. vol. 325, pp. 2529–2535 (2020)
7 Supplementary Material
7.1 Methodology: Details
7.1.1 is_counterfactual: Checks for Goal State/ Counterfactual State
The function is_counterfactual is our algorithmic implementation of checking if a state from definition 8. In Algorithm 3, we specify the pseudo-code for a function is_counterfactual which takes as arguments a state , a set of causal rules , and a set of Decision rules . The function checks if a state is a counterfactual/goal state. By definition is_counterfactual is for state that is causally consistent with all and does not agree with the any decision rules .
(11) |
7.1.2 Intervene: Transition Function for moving from the current state to the new state
-
•
Causal Action: gets altered to a causally consistent new state . OR
-
•
Direct Action: new state is obtained by altering 1 feature value of .
The function intervene is our algorithmic implementation of the transition function from definition 6. In Algorithm 4, we specify the pseudo-code for a function intervene, which takes as arguments an Initial State that is causally consistent, a set of Causal Rules , and a set of actions . It is called by find_path in line 4 of algorithm 1.
The function intervene acts as a transition function that inputs a list visited_states containing the current state as the last element, and returns the new state by appending to visited_states. The new state is what the current state traverses. Additionally, the function intervene ensures that no states are revisited. In traversing from to , if there are a series of intermediate states that are not causally consistent, it is also included in visited_states, thereby depicting how to traverse from one causally consistent state to another.
7.1.3 Update
-
•
Causal Action: gets altered to a causally consistent new state . OR
-
•
Direct Action: new state is obtained by altering 1 feature value of .
In Algorithm 5, we specify the pseudo-code for a function update, that given a state , list actions_taken, list visited_statesand given an action , appends to actions_taken. It also appends the list actions_taken as well as the new resultant state resulting from the action to the list visited_states. The list actions_taken is used to track all the actions attempted from the current state to avoid repeating them. The function update is called by both functions intervene and make_consistent.
7.1.4 Candidate Path
Given the CFG constructed from a run of algorithm 1 and the return value that we refer to as such that r is a list (algorithm succeeds). is the resultant list obtained from removing all elements containing states . We can construct the corresponding candidate path as follows: represents the th element of list . The candidate path is the sequence of states , where is the length of list . is the state corresponding to for .
7.2 Proofs
Theorem 7.1
Soundness Theorem
Given a CFG , constructed from a run of algorithm 1 and a corresponding candidate path , is a solution path for .
Proof
Let be a goal set for . By definition 11, , where . By definition 9 we must show has the following properties.
1)
2)
3)
4)
5)
1) By definition 4, is causally consistent and cannot be removed from the candidate path. Hence I must be in the candidate path and is the first state as per line 2 in algorithm 1. Therefore must be .
2) The while loop in algorithm 1 ends if and only if is True. From theorem 7.2, is True only for the goal state. Hence .
3) By definition 11 of the candidate path, all states .
4) By theorem 7.4, we have proved the claim .
5) By theorem 7.3, we have proved the claim .
Hence we proved the candidate path (definition 11) is a solution path (definition 9).
Theorem 7.2
Given a CFG , constructed from a run of algorithm 1, with goal set , and ; will be if and only if .
Proof
By the definition of the goal set we have
(12) |
For which takes as input the state , the set of causal rules and the set of decision rules (Algorithm 3), we see that by from line 1 in algorithm 3, it returns if it satisfied all rules in and no rules in .
By the Definition 3, if and only if it satisfies a rule in . Therefore, is if and only if and since and , then .
Theorem 7.3
Given a CFG , constructed from a run of algorithm 1 and a corresponding candidate path ;
Proof
This property can be proven by induction on the length of the list visited_lists obtained from Algorithm 1, 2, and 4.
Base Case: The list visited_lists from algorithm 1 has length of 1, i.e., []. The property is trivially true as there is no .
Inductive Hypotheses:
We have a list [] of length generated from or more iteration of running the function intervene (algorithm 4), and it satisfies the claim
Inductive Step: If we have a list [] of length n and we wish to get element obtained through running another iteration of function intervene (algorithm 4). Since [] is of length n by the inductive hypothesis, it satisfies the property, and it is sufficient to show where .
The list visited_lists from algorithm 1 has length of . Going from to involves calling the function intervene (Algorithm 4) which in turn calls the function make_consistent (Algorithm 2).
Function make_consistent (Algorithm 2) takes as input the state , the list of actions taken actions_taken, the list of visited states visited_states, the set of causal rules and the set of possible actions . It returns visited_states with the new causally consistent states as the last element. From line 1, if we pass as input a causally consistent state, then function make_consistent does nothing. On the other hand, if we pass a causally inconsistent state, it takes actions to reach a new state. Upon checking if the action taken results in a new state that is causally consistent from the while loop in line 1, it returns the new state. Hence, we have shown that the moment a causally consistent state is encountered in function make_consistent, it does not add any new state.
Function intervene (Algorithm 4) takes as input the list of visited states visited_states which contains the current state as the last element, the set of causal rules and the set of possible actions . It returns visited_states with the new causally consistent states as the last element. It calls the make_consistent function. For the function intervene, in line 1 it obtains the current state (in this case ) from the list visited_states. It is seen in line 2 that an action is taken:
1) Case 1: If a causal action is taken, then upon entering the the function make_consistent (Algorithm 2), it will not do anything as causal actions by definition result in causally consistent states.
2) Case 2: If a direct action is taken, then the new state that may or may not be causally consistent is appended to visited_states. The call to the function make_consistent will append one or more states with only the final state appended being causally consistent.
Hence we have shown that the moment a causally consistent state is appended in function intervene, it does not add any new state. This causally consistent state is . In both cases as defined in Definition 10 and this .
Theorem 7.4
Given a CFG problem , constructed from a run of algorithm 1, with goal set and a corresponding candidate path with , .
Proof
This property can be proven by induction on the length of the list visited_lists obtained from Algorithm 1, 2, and 4.
Base Case: visited_lists has length of 1.
Therefore the property with , is trivially true as state for does not exist.
Inductive Hypotheses:
We have a list [] of length generated from or more iteration of running the function intervene (Algorithm 4), and it satisfies the claim .
Inductive Step: Suppose we have a list [] of length n and we wish to append the n+1 th element (state ) by calling the function intervene, and we wish to show that that the resultant list satisfies the claim . The first n-1 elements () are not in as per the inductive hypothesis.
From line 3 in the function find_path (Algorithm 1), we see that to call the function intervene another time, the current state (in this case cannot be a counterfactual, by theorem 7.2. Hence
Therefore by induction the claim holds.
7.3 Experimental Setup
7.3.1 Counterfactuals
Algorithm 3 is_counterfactual returns True for all states consistent with causal rules that disagree with the decision rules . Given our state space , from is_counterfactual, we obtain all states that are realistic counterfactuals. Table 2 shows the number of counterfactuals that we obtain using is_counterfactual.
Dataset | # of Features Used | # of Counterfactuals |
---|---|---|
Adult | 6 | 112 |
Cars | 4 | 78 |
German | 7 | 240 |
7.3.2 Dataset: Cars
The Car Evaluation dataset provides information on car purchasing acceptability. We relabelled the Car Evaluation dataset to ‘acceptable’ and ‘unacceptable’ in order to generate the counterfactuals. We applied the CoGS methodology to rules generated by the FOLD-SE algorithm. These rules indicate whether a car is acceptable to buy or should be rejected, with the undesired outcome being rejection.
For the Car Evaluation dataset, table 1) shows a path from initial rejection to changes that make the car acceptable for purchase.
We run the FOLD-SE algorithm to produce the following rules:
label(X,‘negative’) :- persons(X,‘2’).
label(X,‘negative’) :- safety(X,‘low’).
label(X,‘negative’) :- buying(X,‘vhigh’), maint(X,‘vhigh’).
label(X,‘negative’) :- not buying(X,‘low’), not buying(X,‘med’),
maint(X,‘vhigh’).
label(X,‘negative’) :- buying(X,‘vhigh’), maint(X,‘high’).
The rules described above indicate if the purchase of a car was rejected .
-
1.
Accuracy: 93.9%
-
2.
Precision: 100%
-
3.
Recall: 91.3%
2) Features and Feature Values used:
-
•
Feature: persons
-
•
Feature: safety
-
•
Feature: buying
-
•
Feature: maint
7.3.3 Dataset: Adult
The Adult dataset includes demographic information with labels indicating income (‘’ or ‘’). We applied the CoGS methodology to rules generated by the FOLD-SE algorithm on the Adult dataset [5]. These rules indicate whether someone makes ‘$50k/year’.
Additionally, causal rules are also learnt and verified (for example, if feature ‘Marital Status’ has value ‘Never Married’, then feature ‘Relationship’ should (not) have the value ‘husband’ or ‘wife’. We learn the rules to verify these assumptions on cause-effect dependencies.
The goal of CoGS is to find a path to a counterfactual instance where a person makes ‘$50k/year’.
For the Adult dataset, Table 1 shows a path from making ‘$50k/year’ to ‘$50k/year’.
We run the FOLD-SE algorithm to produce the following decision making rules:
label(X,‘<=50K’) :- not marital_status(X,‘Married-civ-spouse’),
capital_gain(X,N1), N1=<6849.0.
label(X,‘<=50K’) :- marital_status(X,‘Married-civ-spouse’),
capital_gain(X,N1), N1=<5013.0,
education_num(X,N2), N2=<12.0.
-
1.
Accuracy: 84.5%
-
2.
Precision: 86.5%
-
3.
Recall: 94.6%
2) FOLD-SE gives Causal rules for the ‘marital_status’ feature having value ‘never_married’:
marital_status(X,‘Never-married’) :- not relationship(X,‘Husband’),
not relationship(X,‘Wife’), age(X,N1), N1=<29.0.
-
1.
Accuracy: 86.4%
-
2.
Precision: 89.2%
-
3.
Recall: 76.4%
3) FOLD-SE gives Causal rules for the ‘marital_status’ feature having value ‘Married-civ-spouse’:
marital_status(X,‘Married-civ-spouse’) :- relationship(X,‘Husband’).
marital_status(X,‘Married-civ-spouse’) :- relationship(X,‘Wife’).
-
1.
Accuracy: 99.1%
-
2.
Precision: 99.9%
-
3.
Recall: 98.2%
4) For values of the feature ‘marital_status’ that are not ‘Married-civ-spouse’ or ‘never_married’ which we shall call ‘neither’, a user defined rule is used:
marital_status(X,neither) :- not relationship(X,‘Husband’),
not relationship(X,‘Wife’).
5) FOLD-SE gives Causal rules for the ‘relationship’ feature having value ‘husband’:
relationship(X,‘Husband’) :- sex(X,‘Male’) ,
age(X,N1), not(N1=<27.0).
-
1.
Accuracy: 82.3%
-
2.
Precision: 71.3%
-
3.
Recall: 93.2%
5) For the ‘relationship’ feature value of ‘wife’, a user defined rule is used:
relationship(X,‘Wife’) :- sex(X,‘Female’).
6)Features Used in Generating the counterfactual path:
-
•
Feature: marital_status
-
•
Feature: relationship
-
•
Feature: sex
-
•
capital_gain
-
•
education_num
-
•
age
7.3.4 Dataset: German
We run the FOLD-SE algorithm to produce the following decision making rules:
label(X,‘good’):-checking_account_status(X,‘no_checking_account’)
label(X,‘good’):-not checking_account_status(X,‘no_checking_account’),
not credit_history(X,‘all_dues_atbank_cleared’),
duration_months(X,N1), N1=<21.0,
credit_amount(X,N2), not(N2=<428.0),
not ab1(X,‘True’).
ab1(X,‘True’):-property(X,‘car or other’),
credit_amount(X,N2), N2=<1345.0.
-
1.
Accuracy: 77%
-
2.
Precision: 83%
-
3.
Recall: 84.2%
2) FOLD-SE gives Causal rules for the ‘present_employment_since’ feature having value ‘employed’ where employed is the placeholder for all feature values that are not equal to the feature value ‘unemployed’:
present_employment_since(X,‘employed’) :-
not job(X,‘unemployed/unskilled-non_resident’).
-
1.
Accuracy: 95%
-
2.
Precision: 96.4%
-
3.
Recall: 98.4%
3) For values of the feature ‘present_employment_since’ that are ‘unemployed’, a user defined rule is used
present_employment_since(X,‘unemployed’) :-
job(X,‘unemployed/unskilled-non_resident’).
6)Features Used in Generating the counterfactual path:
-
•
checking_account_status
-
•
credit_history
-
•
property
-
•
duration_months
-
•
credit_amount
-
•
present_employment_since
-
•
job