<jupyter_start><jupyter_text>Single-decision CID Incentives In this tutorial, we demonstrate how to find which nodes in a single-decision CID face which type of incentive.We will concentrate on the incentives defined in "Agent Incentives: A Causal Perspective" by <NAME>, <NAME>, <NAME>, <NAME>, and <NAME> (2021) which we will refer to as the "AI:ACP" paper.The incentives we can find using our codebase are:- A) Value of information- B) Response Incentives- C) Value of Control (nodes can be specified further as admitting indirect or direct Value of Control).- D) Instrumental Control IncentivesWe shall give provide each incentive's graphical criterion as we go, and demonstrate how to use our codebase to find them with the same examples that were used in AI:ACP.Note: Because AI:ACP proved that all of these incentives are sound and complete, we can work with unparameterised CIDs throughout this tutorial.<jupyter_code>#importing necessary libraries
%load_ext autoreload
%autoreload 2
%matplotlib inline
%autosave 60
import sys
sys.path.append("..") #TODO: make /cid a package, then delete this
import numpy as np
from core.cid import CID
from core.cpd import UniformRandomCPD, FunctionCPD, DecisionDomain
from analyze.value_of_information import admits_voi, admits_voi_list
from analyze.response_incentive import admits_ri, admits_ri_list
from analyze.value_of_control import admits_voc, admits_voc_list
from analyze.instrumental_control_incentive import admits_ici, admits_ici_list<jupyter_output><empty_output><jupyter_text>A) Value of Information A variable has __positive value of information (VoI)__ if a decision-maker would benefit from knowing its value before making a decision.Its graphical criteria is:>A single-decision CID $G$ admits __positive value of information__ for $X\in\textbf{V}$ if and only if:1. $X \neq D$2. $X \notin \textbf{Desc}(D)$3. $X \not\perp U | (Pa_D ∪ {D} \setminus {X})$ where $U \in \textbf{U} \cap \textbf{Desc}(D)$ To demonstrate this concept, we will consider AI:ACP's __Grade prediction example__: _To decide which applicants to admit, a university uses a model to predict the grades of new students. The university would like the system to predict accurately, without treating students differently based on their gender or race. The prediction model uses the gender of the student and the high school they attended to make its grade prediction. We want to know whether the predictor is incentivised to behave in a discriminatory manner with respect to the students’ gender and race. In this hypothetical cohort of students we make the following assumptions:_- Performance at university is evaluated by a student's grades and this is a function of the quality of the high-school education the student received. - A student’s high-school is assumed to be impacted by their race, and so this can affect the quality of their education. - - Gender, however, is assumed not to have an effect on the high school they attended. A CID for this example is defined and drawn below where:- R = Race- HS = High School- E = Education- Gr = Grade- Ge = Gender- P = Predicted Grade  [decision node]- Ac = Accuracy [utility node]<jupyter_code>cid = CID([
    ('R', 'HS'),
    ('HS', 'E'),
    ('HS', 'P'),
    ('E', 'Gr'),
    ('Gr', 'Ac'),
    ('Ge', 'P'),
    ('P', 'Ac'),
    ],
    decision_nodes=['P'],
    utility_nodes=['Ac']
    )
cid.draw()<jupyter_output><empty_output><jupyter_text>To determine which nodes have positive value of information for the predictor model making a grade prediction (node 'P') in such a way as to maximise its accuracy ('Ac'):<jupyter_code>admits_voi_list(cid, 'P')<jupyter_output><empty_output><jupyter_text>We can show this visually:<jupyter_code>cid.draw_property(lambda node: admits_voi(cid, 'P', node))<jupyter_output><empty_output><jupyter_text>Therefore, the prediction model would benefit from knowing the value of "High School', 'Education', and the student's true 'Grade' before making a grade prediction. We can also ask whether an individual node offers positive value of information:<jupyter_code>admits_voi(cid, 'P', 'HS')
admits_voi(cid, 'P', 'R')<jupyter_output><empty_output><jupyter_text>B) Response Incentives A variable has a __response incentive__ if a decision-maker benefits from making its decision causally responsive to the variable (AI:ACP) Before we introduce the graphical criterion for a response incentive, we need to introduce the concept of a nonrequisite observation (Lauritzen and Nilsson, 2001) A __nonrequisite observation link__ in a single-decision CID $G$ is any edge $W \rightarrow D$ such that $W \perp U | (Pa_D ∪ {D} \setminus {W})$.(where $U\in Desc(D)$)>The __requisite graph__, $G^*$, of a single-decision CID $G$ is the result of removing from $G$ all nonrequisite observation links.Note: this is the same as removing all edges from D to any of its parent nodes that do not admit positive value of informationAlso note: a requisite graph is also known as a __minimal reduction__, __trimmed_graph__, or __d-reduction__. Following from this, we arrive at the graphical criterion for a response incentive (AI:ACP): >A single-decision CID G admits a __response incentive__ on $X \in \textbf{V}$ if and only if the requisite graph $G^∗$ has a directed path $X \rightarrow D$. To demonstrate this concept, we will again consider the __Grade prediction example__ (descibed above)<jupyter_code>cid = CID([
    ('R', 'HS'),
    ('HS', 'E'),
    ('HS', 'P'),
    ('E', 'Gr'),
    ('Gr', 'Ac'),
    ('Ge', 'P'),
    ('P', 'Ac'),
    ],
    decision_nodes=['P'],
    utility_nodes=['Ac']
    )
cid.draw()<jupyter_output><empty_output><jupyter_text>To find all the nodes in this CID that admit a responce incentive:<jupyter_code>admits_ri_list(cid, 'P')
cid.draw_property(lambda node: admits_ri(cid, 'P', node))<jupyter_output><empty_output><jupyter_text>Again, we can test whether an individual node admits a responce incentive:<jupyter_code>admits_ri(cid, 'P', 'R')<jupyter_output><empty_output><jupyter_text>AI:ACP argue that a response incentive on a sensitive attribute can be problematic from a fairness perspective. A decision is considered counterfactually unfair if a change to a sensitive attribute, such as race or gender, would change the decision. Therefore, a response incentive on a sensitve attribute indicates that counterfactual unfairness is incentivised; it implies that all optimal policies are counterfactually unfair. AI:ACP propose redesigning the grade-predictor by removing the predictor's access to knowledge about the student's high school ('HS'->'P') because this means that there will no longer be a response incentive on a sensitive attribute.<jupyter_code>cid = CID([
    ('R', 'HS'),
    ('HS', 'E'),
    ('E', 'Gr'),
    ('Gr', 'Ac'),
    ('Ge', 'P'),
    ('P', 'Ac'),
    ],
    decision_nodes=['P'],
    utility_nodes=['Ac']
    )
cid.draw_property(lambda node: admits_ri(cid, 'P', node))<jupyter_output><empty_output><jupyter_text>After the change, we can see that no node in the CID for the system admits a response incentive!  C) Value of Control A variable has positive __value of control (VoC)__ if a decision-maker could benefit from choosing that variable's value.Its graphical criterion (AI:ACP) is:>A single-decision CID $G$ admits __positive value of control__ for a node $X \in V \setminus {D}$ if and only if there is a directed path $X \rightarrow U$ in the requisite graph $G^*$. To demonstrate this incentive, we introduce another example from AI:ACP. __Content recommendation example:__ _An AI algorithm has the task of recommending a series ries of posts to a user. The designers want the posts to match the user’s interests, to maximise the number of posts the user clicks on. However, they do not want the algorithm to present polarising content to manipulate the user into clicking more predicatably._- O = Original user opinions- I = Influences user opinions- M = Model of original opinions- P = Posts to show [decision node]- C = Clicks [utility node]<jupyter_code>cid = CID([
        ('O', 'M'),
        ('O', 'I'),
        ('M', 'P'),
        ('P', 'I'),
        ('I', 'C'),
        ('P', 'C'),
        ],
        decision_nodes=['P'],
        utility_nodes=['C']
        )
cid.draw()<jupyter_output><empty_output><jupyter_text>We then can use similar functions to what we used for VoI and RI:<jupyter_code>admits_voc_list(cid)
cid.draw_property(lambda node: admits_voc(cid, node))<jupyter_output><empty_output><jupyter_text>Instrumental Control Incentive The final single-decision CID incentive that we shall introduce in this tutorial is the concept of an __instrumental_control_incentive__. The concept can be intuitively understood as follows. If the agent got to choose $D$ to influence $X$ independently of how $D$ influences other aspects of the environment, would that choice matter? In other words, is controlling $X$ instrumentally useful for maximising utility?Its graphical criterion (AI:ACP) is:>A single-decision CID $G$ admits an __instrumental_control_incentive__ for a node $X \in V$ if and only if $G$ has a directed path from the decision $D$ to a utility node $U \in \textbf{U}$ that passes through $X$. Using the __content_reccomendation_example__ again to demonstrate this criterion:<jupyter_code>cid = CID([
        ('O', 'M'),
        ('O', 'I'),
        ('M', 'P'),
        ('P', 'I'),
        ('I', 'C'),
        ('P', 'C'),
        ],
        decision_nodes=['P'],
        utility_nodes=['C']
        )
cid.draw()<jupyter_output><empty_output><jupyter_text>We determine which nodes admit instrumental control incentives in the now familiar way:<jupyter_code>admits_ici_list(cid, 'P')
cid.draw_property(lambda node: admits_ici(cid, 'P', node))<jupyter_output><empty_output><jupyter_text>We can understand from this that because "I (influenced user opinions)" has an instumental control incentive, the content reccomender may seek to influence that variable in order to attain utility. AI:ACP offer an alternative content reccomender design that avoids this undesirable behaviour. Instead of being rewarded for the true click through rate, the content reccomender is rewarded for the clicks it would be predicted to have, based on a separately trained model of the user's preferences. The modified CID for this changed model is the following:- O = Original user opinions- I = Influences user opinions- M = Model of original opinions- P = Posts to show [decision node]- PC = Predicted Clicks [utility node]<jupyter_code>cid = CID([
        ('O', 'M'),
        ('O', 'I'),
        ('M', 'P'),
        ('M', 'PC'),
        ('P', 'I'),
        ('P', 'PC'),
        ],
        decision_nodes=['P'],
        utility_nodes=['PC']
        )
cid.draw()<jupyter_output><empty_output><jupyter_text>We observe that 'PC' (Predicted clicks) still has an instumental control incentive so the content reccomender would still deliver desired content, but 'I' (Influnces user opinion) no longer has this incentive, as required.<jupyter_code>cid.draw_property(lambda node: admits_ici(cid, 'P', node))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0969194739686543, 'fraction_numerical': 0.0012610340479192938, 'mean_word_length': 4.737984496124031, 'pattern_counts': {'":': 0, '<': 66, '<?xml version=': 0, '>': 72, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '15', 'dir': 'jupyter-structured-clean-dedup', 'id': '625629', 'license': 'Apache-2.0', 'n_tokens_mistral': 3300, 'n_tokens_neox': 3149, 'n_words': 1398, 'path': 'notebooks/CID_Incentives_Tutorial.ipynb', 'repo_name': 'edlanglois/pycid', 'size': '11130'}