speice.io/assets/js/5f602fa1.736c5ad0.js

1 line
168 KiB
JavaScript
Raw Normal View History

"use strict";(self.webpackChunkspeice_io=self.webpackChunkspeice_io||[]).push([["8345"],{50084:function(s,e,a){a.r(e),a.d(e,{assets:function(){return m},contentTitle:function(){return r},default:function(){return d},frontMatter:function(){return t},metadata:function(){return l},toc:function(){return c}});var l=a(54018),n=a(85893),i=a(50065);let t={slug:"2016/05/the-unfair-casino",title:"The unfair casino",date:new Date("2016-05-15T12:00:00.000Z"),authors:["bspeice"],tags:[]},r=void 0,m={authorsImageUrls:[void 0]},c=[{value:"Proving we can detect cheating",id:"proving-we-can-detect-cheating",level:2},{value:"The Edge Cases",id:"the-edge-cases",level:2},{value:"Edge Case 1",id:"edge-case-1",level:3},{value:"Edge Case 2",id:"edge-case-2",level:3},{value:"Detection Conclusion",id:"detection-conclusion",level:2},{value:"Simulated Annealing",id:"simulated-annealing",level:2},{value:"Deriving the Likelihood function",id:"deriving-the-likelihood-function",level:3},{value:"The process of Simulated Annealing",id:"the-process-of-simulated-annealing",level:3},{value:"The actual code",id:"the-actual-code",level:2},{value:"Catching the Casino",id:"catching-the-casino",level:2},{value:"Attempt 1",id:"attempt-1",level:3},{value:"Attempt 2",id:"attempt-2",level:3},{value:"Attempt 3",id:"attempt-3",level:3},{value:"Attempt 4",id:"attempt-4",level:3},{value:"Attempt 5",id:"attempt-5",level:3},{value:"Conclusion",id:"conclusion",level:2},{value:"Justification of Simulated Annealing",id:"justification-of-simulated-annealing",level:2},{value:"Why Simulated Annealing?",id:"why-simulated-annealing",level:3},{value:"Why not something else?",id:"why-not-something-else",level:3}];function h(s){let e={a:"a",annotation:"annotation",code:"code",em:"em",h2:"h2",h3:"h3",hr:"hr",img:"img",li:"li",math:"math",mi:"mi",mn:"mn",mo:"mo",mrow:"mrow",mstyle:"mstyle",msub:"msub",mtable:"mtable",mtd:"mtd",mtr:"mtr",munderover:"munderover",ol:"ol",p:"p",path:"path",pre:"pre",semantics:"semantics",span:"span",strong:"strong",svg:"svg",...(0,i.a)(),...s.components};return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:"Trying to figure out how exactly two dice are loaded in a cheating casino."}),"\n",(0,n.jsx)(e.p,{children:"In the ongoing eternal cycle of mathematicians asking generally useless questions about probability, I dreamt up another one. The scenario is as follows:"}),"\n",(0,n.jsx)(e.p,{children:(0,n.jsx)(e.strong,{children:"You're playing a game with two die, and you do not get to see what the outcome of the die are on each roll. All you get to see is their sum. Given an arbitrarily long list of the sum of two rolls, can you determine if one or both die are loaded, and what those loadings are?"})}),"\n",(0,n.jsx)(e.h2,{id:"proving-we-can-detect-cheating",children:"Proving we can detect cheating"}),"\n",(0,n.jsx)(e.p,{children:"My first question is simply, is this possible? There's a lot of trivial cases that make it obvious that there's cheating going on. But there are some edge cases that might give us more difficulty. First though, let's get a picture of what the fair distribution looks like. In principle, we can only detect cheating if the distribution of the fair die differs from the distribution of the loaded die."}),"\n",(0,n.jsx)(e.pre,{children:(0,n.jsx)(e.code,{className:"language-python",children:"import numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\n%matplotlib inline\n\nfair_1 = np.random.randint(1, 7, 10000)\nfair_2 = np.random.randint(1, 7, 10000)\n\npd.Series(fair_1 + fair_2).plot(kind='hist', bins=11);\nplt.title('Fair Distribution');\n"})}),"\n",(0,n.jsx)(e.p,{children:(0,n.jsx)(e.img,{alt:"png",src:a(68960).Z+"",width:"400",height:"266"})}),"\n",(0,n.jsxs)(e.p,{children:["This distribution makes sense: there are many ways to make a 7 (the most frequent observed value) and very few ways to make a 12 or 2; an important symmetry. As a special note, you can notice that the sum of two fair dice is a discrete case of the ",(0,n.jsx)(e.a,{href:"https://en.wikipedia.org/wiki/Triangular_distribution",children:"Tri