{"id":154,"date":"2015-02-21T01:01:03","date_gmt":"2015-02-21T01:01:03","guid":{"rendered":"http:\/\/aristotle2digital.blogwyrm.com\/?p=154"},"modified":"2015-02-21T01:01:03","modified_gmt":"2015-02-21T01:01:03","slug":"aces-high","status":"publish","type":"post","link":"https:\/\/aristotle2digital.blogwyrm.com\/?p=154","title":{"rendered":"Aces High"},"content":{"rendered":"<p>This week\u2019s column has a three-fold inspiration.\u00a0 First off, most of the most exciting and controversial philosophical endeavors always involve arguing from incomplete or imprecise information to a general conclusion.\u00a0 These inferences fall under the heading of either inductive or abductive reasoning, and most of the real sticking points in modern society (or any society for that matter) revolve around how well a conclusion is supported by fact and argument.\u00a0 The second source comes from my recent dabbling in artificial intelligence.\u00a0 I am currently taking the edx course CS188.1x, and the basic message is that the real steps forward that have been taking shape in the AI landscape came after the realization was made that computers must be equipped to handle incomplete, noisy, and inconsistent data.\u00a0 Statistical analysis and inference deals, by design, with such data, and its use allows for an algorithm to make a rational decision in such circumstances.\u00a0 The final inspiration came from a fall meeting of my local AAPT chapter in which Carl Mungan of the United States Naval Academy gave a talk.\u00a0 His discussion of the <a href=\"http:\/\/usna.edu\/Users\/physics\/mungan\/_files\/documents\/Scholarship\/TwoAces.pdf\">two aces problem<\/a> was nicely done, and I decided to see how to produce code in Python that would \u2018experimentally\u2019 verify the results.<\/p>\n<p>Before presenting the various pieces of code, let\u2019s talk a bit about the problem.\u00a0 This particular problem is due to Boas in her book <em><a href=\"http:\/\/www.amazon.com\/Mathematical-Methods-Physical-Sciences-Mary\/dp\/0471198269\/ref=sr_1_1?ie=UTF8&amp;qid=1424050699&amp;sr=8-1&amp;keywords=boas+physics\">Mathematical Methods for the Physical Sciences<\/a><\/em>, and goes something like this:<\/p>\n<div style=\"background-color: #ff6666; border: solid 1px black;\">What is the probability that, when being dealt two random cards from a standard deck, the two cards will be two aces?\u00a0 Suppose that one of the cards is known to be an ace, what is the probability?\u00a0 Suppose that one of the cards is known to be the ace of spades, what is the probability?<\/div>\n<p>&nbsp;<\/p>\n<p>The first part of this three-fold problem is very well defined and relatively simple to calculate.\u00a0 The second two parts require some clarification of the phrase \u2018is known to be\u2019.\u00a0 The first possible interpretation is that the player separates out the aces from the deck and either chooses one of them at random (part 2) or he chooses the ace of spades (part 3).\u00a0 He returns the remaining 3 aces to the deck, which he subsequently shuffles prior to drawing the second card.\u00a0 I will refer to this method as the <strong><em>solitaire option<\/em><\/strong>.\u00a0 The second possible interpretation (due to Mungan) is that a dealer draws two cards at random and examines them both while keeping their identity hidden from the player.\u00a0 If one of the cards is an ace (part 2) or is the ace of spades (part 3), the dealer then gives the cards to the player.\u00a0 Parts 2 and 3 of the question then ask for the probability that the hands that pass this inspection step actually have two aces.\u00a0 Since this last process involves assistance from the dealer, I will refer to it as the <strong><em>assisted option<\/em><\/strong>.\u00a0 Finally, all probabilities will be understood from the frequentist point of view.\u00a0 That is to say that each probability will be computed as a ratio of desired outcomes to all possible outcomes.<\/p>\n<p>With those preliminary definitions out of the way, let\u2019s compute some probabilities by determining various two-card hand outcomes.<\/p>\n<p>First let\u2019s calculate the number of possible two-card hands.\u00a0 Since there are 52 choices for the first card and 51 for the second, there are 52&#215;51\/2 = 1326 possible two-card hands.\u00a0 Of these, there are 48&#215;47\/2 = 1128 possible two-card hands with no aces, since the set of cards without the aces is comprised of 48 cards.\u00a0 Notice that, in both of these computations, we divide by 2 to account for the fact that order doesn\u2019t matter.\u00a0 For example, a 2 of clubs as the first card and a 3 of diamonds as the second is the same hand as a 3 of diamonds as the first card and a 2 of clubs as the second.<\/p>\n<p><a href=\"http:\/\/aristotle2digital.blogwyrm.com\/wp-content\/uploads\/2015\/02\/no_aces.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-158\" src=\"http:\/\/aristotle2digital.blogwyrm.com\/wp-content\/uploads\/2015\/02\/no_aces.jpg\" alt=\"no_aces\" width=\"633\" height=\"651\" srcset=\"https:\/\/aristotle2digital.blogwyrm.com\/wp-content\/uploads\/2015\/02\/no_aces.jpg 633w, https:\/\/aristotle2digital.blogwyrm.com\/wp-content\/uploads\/2015\/02\/no_aces-291x300.jpg 291w\" sizes=\"auto, (max-width: 633px) 100vw, 633px\" \/><\/a><\/p>\n<p>Likewise, there are 48&#215;4 = 192 ways of getting a hand with only 1 ace.\u00a0 Note that there is no need to divide by 2, since the two cards are drawn from two different sets.<\/p>\n<p><a href=\"http:\/\/aristotle2digital.blogwyrm.com\/wp-content\/uploads\/2015\/02\/one_ace.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-157\" src=\"http:\/\/aristotle2digital.blogwyrm.com\/wp-content\/uploads\/2015\/02\/one_ace.jpg\" alt=\"one_ace\" width=\"680\" height=\"489\" srcset=\"https:\/\/aristotle2digital.blogwyrm.com\/wp-content\/uploads\/2015\/02\/one_ace.jpg 680w, https:\/\/aristotle2digital.blogwyrm.com\/wp-content\/uploads\/2015\/02\/one_ace-300x215.jpg 300w\" sizes=\"auto, (max-width: 680px) 100vw, 680px\" \/><\/a><\/p>\n<p>Finally, there are only 6 ways to get a two-ace hand.\u00a0 These are the 6 unique pairs that can be constructed from the green set shown in the above figure.<\/p>\n<p>As a check, we should sum the size of the individual set and confirm that it equals the size of the total number of two-card hands. This sum is 1128 + 192 + 6 for no-ace, one-ace, and two-ace hands, and it totals 1326, which is equal to the size of the two-card hands.\u00a0 So, the division into subsets is correct.<\/p>\n<p>With the size of these sets well understood, it is reasonably easy to calculate the probabilities asked for in the Boas problem.\u00a0 In addition, we\u2019ll be in a position to determine something about the behavior of the algorithms developed to model the <strong><em>assisted option<\/em><\/strong>.<\/p>\n<p>For part 1, the probability is easy to find as the ratio of all possible two-ace hands (6 of these) to the number of all possible two-card hands (1326 of these).\u00a0 Calculating this ratio gives 6\/1326 = 0.004525 as the probability of pulling a two-ace hand from a random draw from a well-shuffled standard deck.<\/p>\n<p>For parts 2 and 3 in the <strong><em>solitaire option<\/em><\/strong>, the first card is either given to be an ace or the ace of spades.\u00a0 In both cases, the probability of getting another ace is the fraction of times that one of the three remaining aces is pulled from the deck that now holds 51 cards.\u00a0 The probability is then 3\/15 or 0.05882.<\/p>\n<p>The answers for the <strong><em>assisted option<\/em><\/strong> for parts 2 and 3 are a bit more subtle.\u00a0 For part 2, the dealer assists by winnowing the possible set down from 1326 possibilities associated with all two-card hands, to only 192 possibilities associated with all one-ace hands, plus 6 possibilities associated with all two-ace hands.\u00a0 The correct ratio is 6\/198 = 0.03030 as the probability for getting a single hand with two aces when it is known that one is an ace.\u00a0 For part 3, the dealer is even more zealous in his diminishment of the set of possible hands with one card, the ace of spades.\u00a0 After he is done, there are only 51 possibilities, of which 3 are winners, and so the correct ratio is 3\/51 = 0.05882 as the probability of getting a single hand with two aces when it is known that one is the ace of spades.<\/p>\n<p>All of these probabilities are easily checked by writing computer code.\u00a0 I\u2019ve chosen python because it is very easy to perform string concatenation and to append and remove items from lists.\u00a0 The basic data structure is the deck, which is a list of 52 cards constructed from 4 suits (\u2018S\u2019,\u2019H\u2019,\u2019D\u2019,\u2019C\u2019), ranked in traditional bridge order, and 13 cards (\u2018A\u2019,\u20192\u2019,\u20193\u2019,\u20194\u2019,\u20195\u2019,\u20196\u2019,\u20197\u2019,\u20198\u2019,\u20199\u2019,\u201910\u2019,\u2019J\u2019,\u2019Q\u2019,\u2019K\u2019).\u00a0 Picking a card at random is done importing the random package and using random.choice, which returns a random element of a list passed into it as an argument.\u00a0 Using the random package in the code turns the computer modeling into a Monte Carlo simulation.\u00a0 For all cases modeled, I input the number of Monte Carlo trials to be N = 1,000,000.<\/p>\n<p>Code to model part 1 and parts 2 and 3 for the <strong><em>solitaire option<\/em><\/strong> is easy to implement and understand, so I don\u2019t include it here.\u00a0 The Monte Carlo results (10 cases each with N trials) certainly support the analysis done above, but, if one didn\u2019t know how to do the combinatorics, one would only be able to conclude that the results are approximately 0.0045204 +\/- 0.00017.<\/p>\n<p>The code to model parts 2 and 3 for the <strong><em>assisted option<\/em><\/strong> is a bit more involved because the dealer (played by the computer) has to draw a hand then either accept or reject it.\u00a0 Of the N Monte Carlo trials drawn, what percentage of them will be rejected?\u00a0 For part 2, this amounts to determining what the ratio of two-card hands that have at least one ace relative to all the possible two-card hands.\u00a0 This ratio is 192\/1326 = 0.1448.\u00a0 So, roughly 85.5 % of the time the dealer is wasting my time and his.\u00a0 This lack of economy becomes more pronounced when the dealer rejects anything without an ace-of-spades.\u00a0 In this case, the ratio is 51\/1326 = 1\/52 = 0.01923, and approximately 98% of the time the dealer is throwing away the dealt cards because they don\u2019t meet the standard.\u00a0 In both cases, the Monte Carlo results support the combinatoric analysis with 0.03031 +\/- 0.0013 and 0.05948 +\/- 0.0044.<\/p>\n<pre style = \"background-color:#ff6666; border: solid 1px black;\">\r\nimport random                \r\n\r\nsuits   = ['S','H','C','D']\r\ncards   = ['A','2','3','4','5','6','7','8','9','10','J','Q','K']\r\n\r\ndef make_deck():\r\n    deck = []\r\n    for s in suits:\r\n        for c in cards:\r\n            deck.append(c+s)\r\n    return deck\r\n  \r\ndef one_card_ace(num_mc):\r\n    num_times = 0\r\n    num_good  = 0\r\n    deck     = make_deck()\r\n    for i in range(0,num_mc,1):\r\n        card1 = random.choice(deck)\r\n        deck.remove(card1)\r\n        card2 = random.choice(deck)\r\n        deck.append(card1)\r\n        if card1.find('A') == 0 or card2.find('A') == 0:\r\n            num_times = num_times + 1\r\n            if card1.find('A') == 0 and card2.find('A') == 0:\r\n                num_good = num_good + 1\r\n    print deck\r\n    return [num_times, num_good]\r\n\r\ndef ace_of_spades(num_mc):\r\n    num_times = 0\r\n    num_good  = 0\r\n    deck     = make_deck()\r\n    for i in range(0,num_mc,1):\r\n        card1 = random.choice(deck)\r\n        deck.remove(card1)\r\n        card2 = random.choice(deck)\r\n        deck.append(card1)\r\n        if card1.find('AS') == 0:\r\n            num_times = num_times + 1\r\n            if card2.find('A') == 0:\r\n                num_good = num_good + 1\r\n    print deck\r\n    return [num_times,num_good]\r\n<\/pre>\n<p>Notice that the uncertainty in the Monte Carlo results grows larger in part 2 and even larger in part 3.\u00a0 This reflects the fact that the dealer only really affords us about 150,000 and 19,000 trials of useful information due to the rejection process.<\/p>\n<p>Finally, there are a couple of philosophical points to touch on briefly.\u00a0 First, the Monte Carlo results certainly support the frequentist point of view, but they are not actual proofs of the results.\u00a0 Even more troubling is that a set enumeration, such as given above, is not a proof of the probabilities, either.\u00a0 It is a compelling argument and an excellent model, but it presupposes that the probability should be calculated by the ratios as above.\u00a0 Fundamentally, there is no way to actually prove the assumption that set ratios give us the correct probabilities.\u00a0 This assumption rests on the belief that all possible two-card hands are equally likely.\u00a0 This is a very reasonable assumption, but it is an assumption nonetheless. Second, there is often an accompanying statement along the lines that, the more that is known, the higher the likelihood of the result.\u00a0 For example, knowing that one of the cards was an ace increased the likelihood that both were an ace by a factor of 6.7.\u00a0 While true, this statement is a bit misleading, since, in order to know, the dealer had to face the more realistic odds that 82 percent of the time he would be rejecting the hand.\u00a0 So, as the player, our uncertainty was reduced only at the expense of a great deal of effort done on our behalf by another party.\u00a0 This observation has implications for statistical inference that I will explore in a future column.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week\u2019s column has a three-fold inspiration.\u00a0 First off, most of the most exciting and controversial philosophical endeavors always involve arguing from incomplete or imprecise information to a general conclusion.\u00a0&#8230; <a class=\"read-more-button\" href=\"https:\/\/aristotle2digital.blogwyrm.com\/?p=154\">Read more &gt;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-154","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=\/wp\/v2\/posts\/154","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=154"}],"version-history":[{"count":0,"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=\/wp\/v2\/posts\/154\/revisions"}],"wp:attachment":[{"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aristotle2digital.blogwyrm.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}