Changed waterballoon factory function name.

PiperOrigin-RevId: 343283244
This commit is contained in:
Pedro A. Ortega
2020-11-19 15:06:21 +00:00
committed by Saran Tunyasuvunakool
parent cecb85baa5
commit e574fb42a9
@@ -40,11 +40,13 @@
"that causal Bayesian networks cant. Even so, they have received little\n",
"attention from the AI and ML community.\n",
"\n",
"For instance, we can describe a scenario where the weather is the cause and the barometer reading the effect, or viceversa, depending on whether we're on Earth or on some alien planet with different physics:\n",
"For instance, we can describe a scenario where the weather is the cause and the\n",
"barometer reading the effect, or viceversa, depending on whether we're on Earth\n",
"or on some alien planet with different physics:\n",
"\n",
"\u003cimg src=\"http://www.adaptiveagents.org/_media/wiki/probtrees.png\" alt=\"Probability Trees\" width=\"700\"/\u003e\n",
"\n",
"Causal dependencies like these are naturally represented as a tree. We will see later that they allow us representing causal induction.\n",
"Causal dependencies like these are naturally represented as a tree.\n",
"\n",
"In this tutorial we present new algorithms for causal reasoning in discrete\n",
"probability trees that cover the entire causal hierarchy (association,\n",
@@ -3214,11 +3216,18 @@
"source": [
"## Water Balloon Squad (a.k.a. Firing Squad)\n",
"\n",
"The following is a classical example used for illustrating counterfactual reasoning. There are two children (A and B) holding a water balloon, waiting for a signal from their friend (the \"captain\"). Upon the captain's signal, they both throw their water balloon at a single target simultaneously and accurately. The causal dependencies are as shown next:\n",
"The following is a classical example used for illustrating counterfactual\n",
"reasoning. There are two children (A and B) holding a water balloon, waiting\n",
"for a signal from their friend (the \"captain\"). Upon the captain's signal,\n",
"they both throw their water balloon at a single target simultaneously and\n",
"accurately. The causal dependencies are as shown next:\n",
"\n",
"\u003cimg src=\"http://www.adaptiveagents.org/_media/wiki/waterballoon.png\" alt=\"Water Balloon Squad\" width=\"200\"/\u003e\n",
"\n",
"This situation can also be described using a probability tree constructed below. Note that in order to avoid problems due to conditioning on zero-probability transitions, we assign a tiny value (`eps`) to the nearly-impossible transitions.\n",
"This situation can also be described using a probability tree constructed\n",
"below. Note that in order to avoid problems due to conditioning on\n",
"zero-probability transitions, we assign a tiny value (`eps`) to the\n",
"nearly-impossible transitions.\n",
"\n"
]
},
@@ -3232,7 +3241,7 @@
"source": [
"#@title Water Balloon Squad factory function.\n",
"\n",
"def waterballon(bvar, eps=0.0001):\n",
"def waterballoon(bvar, eps=0.0001):\n",
" # Root: defined.\n",
" # Define the captain's signal.\n",
" if 'Captain' not in bvar:\n",
@@ -3301,7 +3310,8 @@
"id": "OfgAR3u0zASo"
},
"source": [
"Let's ask our first question. Assume A throws the water balloon. What is the probability of B having thrown the balloon too?"
"Let's ask our first question. Assume A throws the water balloon.\n",
"What is the probability of B having thrown the balloon too?"
]
},
{
@@ -3312,7 +3322,7 @@
},
"outputs": [],
"source": [
"# Condition on having A throwing the water balloon.\n",
"# Condition on A throwing the water balloon.\n",
"wbs_see = wbs.see(cut_A)\n",
"\n",
"# Print the probability of B throwing the water balloon.\n",
@@ -3329,9 +3339,12 @@
"id": "IALdewe2zWVy"
},
"source": [
"Notice how conditioning changed the transition probabilities, which then allow us to identify the pathways leading up to the event in which B throws the balloon. \n",
"Notice how conditioning changed the transition probabilities, which then \n",
"allow us to identify the pathways leading up to the event in which B throws\n",
"the balloon. \n",
"\n",
"Assume now that A decides to act on their own and throws the balloon. What is the probability of B having thrown the balloon too?"
"Assume now that A decides to act on their own and throws the balloon.\n",
"What is the probability of B having thrown the balloon too?"
]
},
{
@@ -3359,9 +3372,15 @@
"id": "okJ6csZNz-C7"
},
"source": [
"Notice the difference between the two results above. If A acts on their own will, then this alters the conclusions we can draw.\n",
"Notice the difference between the two results above. If A acts on their own\n",
"will, then this alters the conclusions we can draw.\n",
"\n",
"Let's ask a more complex question. **Assume A or B throw the balloon on their own will.** That is, we do not know precisely whether A acted by themself, B acted by themself, or both acted toghether. Intuitively, in this situation it is more likely that B threw the balloon. What is the probability?"
"Let's ask a more complex question. **Assume A or B throw the balloon on their\n",
"own will.** That is, we do not know precisely whether A acted by themself,\n",
"B acted by themself, or both acted together. \n",
"Intuitively, B (or A for that matter) is more likely to having thrown\n",
"the water balloon in this situation than when they were waiting for\n",
"the captain's signal. What is the probability?"
]
},
{
@@ -3389,11 +3408,14 @@
"id": "U6AUPwU8wSoc"
},
"source": [
"The above result shows that it is indeed more likely that B has thrown their water balloon. \n",
"The above result shows that it is indeed more likely (%75) that B has \n",
"thrown their balloon than when they were waiting for the signal (50%). \n",
"\n",
"Now we will ask counterfactual questions. Let us start with an easy one first. \n",
"Now we will ask counterfactual questions. Let's start with an easy one first. \n",
"\n",
"Assume you observe that the target is wet. Then, **had the captain not given the signal**, what is the probability that B threw the water balloon at the target?"
"Assume you observe that the target is wet. Then, **had the captain not given\n",
"the signal**, what is the probability that B would have thrown their water\n",
"balloon at the target?"
]
},
{
@@ -3421,9 +3443,11 @@
"id": "0gifSRkYxDMA"
},
"source": [
"The result shows that B would not have thrown the water balloon, which makes sense, as we assumed that the captain had not given the signal.\n",
"The result shows that B would not have thrown the water balloon.\n",
"This makes sense, as we assumed that B did not get the captain's signal.\n",
"\n",
"Now, assume again you observe that the target is wet. **Had A not thrown the water balloon, would B have thrown it?**"
"Now, assume again you observe that the target is wet. \n",
"**Had A not thrown the water balloon, would B have thrown it?**"
]
},
{
@@ -3451,7 +3475,10 @@
"id": "Jl6rVmjcxqUY"
},
"source": [
"As is shown above, the answer is yes. This is because observing the wet target allows us to conclude that the captain has given the signal. Hence, had A not thrown the water balloon, B must have thrown it."
"As is shown above, the answer is yes. This is because from observing the wet\n",
"target we can conclude that the captain has given the signal. \n",
"Hence, had A not thrown the water balloon, B must have thrown it\n",
"instead. You can verify the causal pathways by inspecting the tree."
]
},
{
@@ -4085,13 +4112,65 @@
],
"metadata": {
"colab": {
"collapsed_sections": [],
"collapsed_sections": [
"qHP8zlWs1OUN",
"XUQVMuc2_VlG",
"P4cjtJaR_VlH",
"KxQFfJio_VlM",
"lcEgcO7C_VlQ",
"BscAftLn_VlZ",
"t9ntPBZd_Vlk",
"Fq63jb0u_Vln",
"afVSi5xo_Vlo",
"ehQ37yPg7Wil",
"9TvtFpta_Vls",
"tZijtGvW_Vlw",
"CRsPVDcg_Vlz",
"HHmLu4w_7e-S",
"rqcodRJr_Vl3",
"1AxBz2Ml_VmG",
"YbYnVRiM_VmJ",
"zyP7gSPl_VmN",
"K7OJKlcZ_VmQ",
"bD3LT8NV7rRV",
"ehK-sadN_VmT",
"ZtQffc1P7wxk",
"5PCmW5ol_VmX",
"CtfxGITj_Vmd",
"-1fUlg1O76bp",
"9ggdcdjg_Vmg",
"Bwc00gKT_Vmj",
"NUy8SH-O7_jT",
"6Y8wjMCi_Vmm",
"RVtd_Pov_Vmt",
"RLijoy-__Vmy",
"2fuYExoQ_Vm1",
"13s9eGWF8FZA",
"9Dmexb79_Vm4",
"RXjEiNWa_VnA",
"qNqHBq19_VnD",
"9JFZjAra8LJd",
"SCZyxF5l_VnG",
"k1vLg3F_8O7c",
"3OMlUFKF_VnM",
"B3DdaUXJ_VnV",
"yxuqdgvA8g-J",
"ioUtMVOs_VnX",
"jWpZ0riB8kG3",
"ZB-JZdum16ZJ",
"jw5OiWWC_Vna",
"ce_kzARO_Vna",
"uZ5o4hHxnUw0",
"_UO1GC7T_Vnl",
"JEuxhMkKHlUm",
"7fTawNEfbNZ1",
"eoNn0c5rj5U1",
"po_krgRljGmp",
"z4icvktpk0v0"
],
"name": "Causality Tutorial.ipynb",
"provenance": [
{
"file_id": "1uLGieQXt93jX0ASo-qSCvnjEV67_4ZOO",
"timestamp": 1591027877583
}
{}
]
},
"kernelspec": {