mirror of
https://github.com/bspeice/speice.io
synced 2024-11-14 22:18:10 -05:00
180 lines
236 KiB
HTML
180 lines
236 KiB
HTML
<!doctype html><html lang=en dir=ltr class="blog-wrapper blog-post-page plugin-blog plugin-id-default" data-has-hydrated=false><meta charset=UTF-8><meta name=generator content="Docusaurus v3.6.0"><title data-rh=true>The unfair casino | The Old Speice Guy</title><meta data-rh=true name=viewport content="width=device-width,initial-scale=1.0"><meta data-rh=true name=twitter:card content=summary_large_image><meta data-rh=true property=og:url content=https://speice.io/2016/05/the-unfair-casino><meta data-rh=true property=og:locale content=en><meta data-rh=true name=docusaurus_locale content=en><meta data-rh=true name=docusaurus_tag content=default><meta data-rh=true name=docsearch:language content=en><meta data-rh=true name=docsearch:docusaurus_tag content=default><meta data-rh=true property=og:title content="The unfair casino | The Old Speice Guy"><meta data-rh=true name=description content="Trying to figure out how exactly two dice are loaded in a cheating casino."><meta data-rh=true property=og:description content="Trying to figure out how exactly two dice are loaded in a cheating casino."><meta data-rh=true property=og:type content=article><meta data-rh=true property=article:published_time content=2016-05-15T12:00:00.000Z><link data-rh=true rel=icon href=/img/favicon.ico><link data-rh=true rel=canonical href=https://speice.io/2016/05/the-unfair-casino><link data-rh=true rel=alternate href=https://speice.io/2016/05/the-unfair-casino hreflang=en><link data-rh=true rel=alternate href=https://speice.io/2016/05/the-unfair-casino hreflang=x-default><script data-rh=true type=application/ld+json>{"@context":"https://schema.org","@id":"https://speice.io/2016/05/the-unfair-casino","@type":"BlogPosting","author":{"@type":"Person","name":"Bradlee Speice"},"dateModified":"2024-11-04T00:16:00.000Z","datePublished":"2016-05-15T12:00:00.000Z","description":"Trying to figure out how exactly two dice are loaded in a cheating casino.","headline":"The unfair casino","isPartOf":{"@id":"https://speice.io/","@type":"Blog","name":"Blog"},"keywords":[],"mainEntityOfPage":"https://speice.io/2016/05/the-unfair-casino","name":"The unfair casino","url":"https://speice.io/2016/05/the-unfair-casino"}</script><link rel=alternate type=application/rss+xml href=/rss.xml title="The Old Speice Guy RSS Feed"><link rel=alternate type=application/atom+xml href=/atom.xml title="The Old Speice Guy Atom Feed"><link rel=stylesheet href=https://cdn.jsdelivr.net/npm/katex@0.13.24/dist/katex.min.css integrity=sha384-odtC+0UGzzFL/6PNoE8rX/SPcQDXBJ+uRepguP4QkPCm2LBxH3FA3y+fKSiJ+AmM crossorigin><link rel=stylesheet href=/assets/css/styles.ae6ff4a3.css><script src=/assets/js/runtime~main.751b419d.js defer></script><script src=/assets/js/main.62ce6156.js defer></script><body class=navigation-with-keyboard><script>!function(){var t,e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return window.localStorage.getItem("theme")}catch(t){}}();t=null!==e?e:"light",document.documentElement.setAttribute("data-theme",t)}(),function(){try{for(var[t,e]of new URLSearchParams(window.location.search).entries())if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script><div id=__docusaurus><div role=region aria-label="Skip to main content"><a class=skipToContent_fXgn href=#__docusaurus_skipToContent_fallback>Skip to main content</a></div><nav aria-label=Main class="navbar navbar--fixed-top"><div class=navbar__inner><div class=navbar__items><button aria-label="Toggle navigation bar" aria-expanded=false class="navbar__toggle clean-btn" type=button><svg width=30 height=30 viewBox="0 0 30 30" aria-hidden=true><path stroke=currentColor stroke-linecap=round stroke-miterlimit=10 stroke-width=2 d="M4 7h22M4 15h22M4 23h22"/></svg></button><a class=navbar__brand href=/><div class=navbar__logo><img src=/img/logo.svg alt="Sierpinski Gasket" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src=/img/logo-dark.svg alt="Sierpinski Gasket" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div><b class="navbar__title text--truncate">The Old Speice Guy</b></a></div><div class="navbar__items navbar__items--right"><a href=https://github.com/bspeice target=_blank rel="noopener noreferrer" class="navbar__item navbar__link header-github-link"></a><div class="toggle_vylO colorModeToggle_DEke"><button class="clean-btn toggleButton_gllP toggleButtonDisabled_aARS" type=button disabled title="Switch between dark and light mode (currently light mode)" aria-label="Switch between dark and light mode (currently light mode)" aria-live=polite aria-pressed=false><svg viewBox="0 0 24 24" width=24 height=24 class=lightToggleIcon_pyhR><path fill=currentColor d="M12,9c1.65,0,3,1.35,3,3s-1.35,3-3,3s-3-1.35-3-3S10.35,9,12,9 M12,7c-2.76,0-5,2.24-5,5s2.24,5,5,5s5-2.24,5-5 S14.76,7,12,7L12,7z M2,13l2,0c0.55,0,1-0.45,1-1s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S1.45,13,2,13z M20,13l2,0c0.55,0,1-0.45,1-1 s-0.45-1-1-1l-2,0c-0.55,0-1,0.45-1,1S19.45,13,20,13z M11,2v2c0,0.55,0.45,1,1,1s1-0.45,1-1V2c0-0.55-0.45-1-1-1S11,1.45,11,2z M11,20v2c0,0.55,0.45,1,1,1s1-0.45,1-1v-2c0-0.55-0.45-1-1-1C11.45,19,11,19.45,11,20z M5.99,4.58c-0.39-0.39-1.03-0.39-1.41,0 c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0s0.39-1.03,0-1.41L5.99,4.58z M18.36,16.95 c-0.39-0.39-1.03-0.39-1.41,0c-0.39,0.39-0.39,1.03,0,1.41l1.06,1.06c0.39,0.39,1.03,0.39,1.41,0c0.39-0.39,0.39-1.03,0-1.41 L18.36,16.95z M19.42,5.99c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06c-0.39,0.39-0.39,1.03,0,1.41 s1.03,0.39,1.41,0L19.42,5.99z M7.05,18.36c0.39-0.39,0.39-1.03,0-1.41c-0.39-0.39-1.03-0.39-1.41,0l-1.06,1.06 c-0.39,0.39-0.39,1.03,0,1.41s1.03,0.39,1.41,0L7.05,18.36z"/></svg><svg viewBox="0 0 24 24" width=24 height=24 class=darkToggleIcon_wfgR><path fill=currentColor d="M9.37,5.51C9.19,6.15,9.1,6.82,9.1,7.5c0,4.08,3.32,7.4,7.4,7.4c0.68,0,1.35-0.09,1.99-0.27C17.45,17.19,14.93,19,12,19 c-3.86,0-7-3.14-7-7C5,9.07,6.81,6.55,9.37,5.51z M12,3c-4.97,0-9,4.03-9,9s4.03,9,9,9s9-4.03,9-9c0-0.46-0.04-0.92-0.1-1.36 c-0.98,1.37-2.58,2.26-4.4,2.26c-2.98,0-5.4-2.42-5.4-5.4c0-1.81,0.89-3.42,2.26-4.4C12.92,3.04,12.46,3,12,3L12,3z"/></svg></button></div><div class=navbarSearchContainer_Bca1><div class=navbar__search><span aria-label="expand searchbar" role=button class=search-icon tabindex=0></span><input id=search_input_react type=search placeholder=Loading... aria-label=Search class="navbar__search-input search-bar" disabled></div></div></div></div><div role=presentation class=navbar-sidebar__backdrop></div></nav><div id=__docusaurus_skipToContent_fallback class="main-wrapper mainWrapper_z2l0"><div class="container margin-vert--lg"><div class=row><aside class="col col--3"><nav class="sidebar_re4s thin-scrollbar" aria-label="Blog recent posts navigation"><div class="sidebarItemTitle_pO2u margin-bottom--md">All posts</div><div role=group><h3>2022</h3><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2011/11/webpack-industrial-complex>The webpack industrial complex</a></ul></div><div role=group><h3>2019</h3><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/12/release-the-gil>Release the GIL</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/09/binary-format-shootout>Binary format shootout</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/06/high-performance-systems>On building high performance systems</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/05/making-bread>Making bread</a></ul><div role=group><h4>Allocations in Rust</h4><ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/02/understanding-allocations-in-rust>Foreword</a><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/02/the-whole-world>Global memory</a><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/02/stacking-up>Fixed memory</a><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/02/a-heaping-helping>Dynamic memory</a><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/02/08/compiler-optimizations>Compiler optimizations</a><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2019/02/summary>Summary</a></ul></ul></div></div><div role=group><h3>2018</h3><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/12/allocation-safety>QADAPT - debug_assert! for allocations</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/12/what-small-business-really-means>More "what companies really mean"</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/10/case-study-optimization>A case study in heaptrack</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/09/isomorphic-apps>Isomorphic desktop apps with Rust</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/09/primitives-in-rust-are-weird>Primitives in Rust are weird (and cool)</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/06/dateutil-parser-to-rust>What I learned porting dateutil to Rust</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/05/hello>Hello!</a></ul><div role=group><h4>Captain's Cookbook</h4><ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/01/captains-cookbook-part-1>Project setup</a><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2018/01/captains-cookbook-part-2>Practical usage</a></ul></ul></div></div><div role=group><h3>2016</h3><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/11/pca-audio-compression>PCA audio compression</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/10/rustic-repodcasting>A Rustic re-podcasting server</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/06/event-studies-and-earnings-releases>Event studies and earnings releases</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a aria-current=page class="sidebarItemLink_mo7H sidebarItemLinkActive_I1ZP" href=/2016/05/the-unfair-casino>The unfair casino</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/04/tick-tock>Tick tock...</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/03/tweet-like-me>Tweet like me</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/03/predicting-santander-customer-happiness>Predicting Santander customer happiness</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/02/profitability-using-the-investment-formula>Profitability using the investment formula</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/02/guaranteed-money-maker>Guaranteed money maker</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/01/cloudy-in-seattle>Cloudy in Seattle</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2016/01/complaining-about-the-weather>Complaining about the weather</a></ul></div><div role=group><h3>2015</h3><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2015/12/testing-cramer>Testing Cramer</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2015/11/autocallable>Autocallable Bonds</a></ul><ul class="sidebarItemList_Yudw clean-list"><li class=sidebarItem__DBe><a class=sidebarItemLink_mo7H href=/2015/11/welcome>Welcome, and an algorithm</a></ul></div></nav></aside><main class="col col--7"><article><header><h1 class=title_f1Hy>The unfair casino</h1><div class="container_mt6G margin-vert--md"><time datetime=2016-05-15T12:00:00.000Z>May 15, 2016</time> · <!-- -->15 min read</div><div class="margin-top--md margin-bottom--sm row"><div class="col col--12 authorCol_Hf19"><div class="avatar margin-bottom--sm"><div class="avatar__intro authorDetails_lV9A"><div class=avatar__name><span class=authorName_yefp>Bradlee Speice</span></div><div class=authorSocials_rSDt><a href=https://github.com/bspeice target=_blank rel="noopener noreferrer" class=authorSocialLink_owbf title=GitHub><svg viewBox="0 0 256 250" width=1em height=1em class="authorSocialLink_owbf githubSvg_Uu4N" style=--dark:#000;--light:#fff preserveAspectRatio=xMidYMid><path d="M128.001 0C57.317 0 0 57.307 0 128.001c0 56.554 36.676 104.535 87.535 121.46 6.397 1.185 8.746-2.777 8.746-6.158 0-3.052-.12-13.135-.174-23.83-35.61 7.742-43.124-15.103-43.124-15.103-5.823-14.795-14.213-18.73-14.213-18.73-11.613-7.944.876-7.78.876-7.78 12.853.902 19.621 13.19 19.621 13.19 11.417 19.568 29.945 13.911 37.249 10.64 1.149-8.272 4.466-13.92 8.127-17.116-28.431-3.236-58.318-14.212-58.318-63.258 0-13.975 5-25.394 13.188-34.358-1.329-3.224-5.71-16.242 1.24-33.874 0 0 10.749-3.44 35.21 13.121 10.21-2.836 21.16-4.258 32.038-4.307 10.878.049 21.837 1.47 32.066 4.307 24.431-16.56 35.165-13.12 35.165-13.12 6.967 17.63 2.584 30.65 1.255 33.873 8.207 8.964 13.173 20.383 13.173 34.358 0 49.163-29.944 59.988-58.447 63.157 4.591 3.972 8.682 11.762 8.682 23.704 0 17.126-.148 30.91-.148 35.126 0 3.407 2.304 7.398 8.792 6.14C219.37 232.5 256 184.537 256 128.002 256 57.307 198.691 0 128.001 0Zm-80.06 182.34c-.282.636-1.283.827-2.194.39-.929-.417-1.45-1.284-1.15-1.922.276-.655 1.279-.838 2.205-.399.93.418 1.46 1.293 1.139 1.931Zm6.296 5.618c-.61.566-1.804.303-2.614-.591-.837-.892-.994-2.086-.375-2.66.63-.566 1.787-.301 2.626.591.838.903 1 2.088.363 2.66Zm4.32 7.188c-.785.545-2.067.034-2.86-1.104-.784-1.138-.784-2.503.017-3.05.795-.547 2.058-.055 2.861 1.075.782 1.157.782 2.522-.019 3.08Zm7.304 8.325c-.701.774-2.196.566-3.29-.49-1.119-1.032-1.43-2.496-.726-3.27.71-.776 2.213-.558 3.315.49 1.11 1.03 1.45 2.505.701 3.27Zm9.442 2.81c-.31 1.003-1.75 1.459-3.199 1.033-1.448-.439-2.395-1.613-2.103-2.626.301-1.01 1.747-1.484 3.207-1.028 1.446.436 2.396 1.602 2.095 2.622Zm10.744 1.193c.036 1.055-1.193 1.93-2.715 1.95-1.53.034-2.769-.82-2.786-1.86 0-1.065 1.202-1.932 2.733-1.958 1.522-.03 2.768.818 2.768 1.868Zm10.555-.405c.182 1.03-.875 2.088-2.387 2.37-1.485.271-2.861-.365-3.05-1.386-.184-1.056.893-2.114 2.376-2.387 1.514-.263 2.868.356 3.061 1.403Z"/></svg></a></div></div></div></div></div></header><div id=__blog-post-container class=markdown><p>Trying to figure out how exactly two dice are loaded in a cheating casino.</p>
|
||
<p>In the ongoing eternal cycle of mathematicians asking generally useless questions about probability, I dreamt up another one. The scenario is as follows:</p>
|
||
<p><strong>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?</strong></p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id=proving-we-can-detect-cheating>Proving we can detect cheating<a href=#proving-we-can-detect-cheating class=hash-link aria-label="Direct link to Proving we can detect cheating" title="Direct link to Proving we can detect cheating"></a></h2>
|
||
<p>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.</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token keyword" style="color:hsl(301, 63%, 40%)">import</span><span class="token plain"> numpy </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">as</span><span class="token plain"> np</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"></span><span class="token keyword" style="color:hsl(301, 63%, 40%)">import</span><span class="token plain"> pandas </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">as</span><span class="token plain"> pd</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"></span><span class="token keyword" style="color:hsl(301, 63%, 40%)">import</span><span class="token plain"> matplotlib</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">pyplot </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">as</span><span class="token plain"> plt</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"></span><span class="token operator" style="color:hsl(221, 87%, 60%)">%</span><span class="token plain">matplotlib inline</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">fair_1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">random</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">randint</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">7</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">10000</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">fair_2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">random</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">randint</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">7</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">10000</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">pd</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">Series</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">fair_1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+</span><span class="token plain"> fair_2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">plot</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">kind</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token string" style="color:hsl(119, 34%, 47%)">'hist'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> bins</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">11</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">;</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">title</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token string" style="color:hsl(119, 34%, 47%)">'Fair Distribution'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">;</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p><img decoding=async loading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REXsoZ6L3sEajUXcKk0Y+i2fls3hWPos903O3tJXkXntPERGdJglPwkn0iIjoQSkgERFRSQpIRERUkgISERGVpIBEjMPAwGwkdf0xMDC77rce8Tw5CitiHIqLIdTx96XKZwtHtCNHYUVERNekgERERCUpIBERUUkKSEREVJICEhERlaSAREREJSkgERFRSQpIRERU0tECIulySUOS1o5q/1NJ90u6T9JFLe1LJK0vnzuxpX2+pLWSfiLps53MOSIi2tPpHsgy4KTWBkkN4L3AMbaPAf6ybJ8HnAbMA04BLi3vgQ7wBeBs23OBuZKes8+IiOi+jhYQ27cDj49qPge4yPZwuc2jZfupwDW2h21vANYDCyQNANNt31VudwWwqJN5R0TE7tUxBzIX+F1Jd0q6TdLryvaZwKaW7baUbTOBzS3tm8u2iIio0d41xTzE9pskvQG4FjhiIgMMDg7uWG40GrnvcUTEKM1mk2azuUf76PjVeCUdDtxg+9hy/UbgYtvfKdfXA28CPgxg+6KyfRWwFNgI3GZ7Xtl+OvA22+eMES9X442OydV4o1dN1qvxqnyM+BbwDgBJc4F9bP8cWAm8T9I+kuYARwJrbG8FnpC0oJxUPwO4vgt5R0TELnR0CEvS1UADeImkByl6FF8Blkm6D3iKoiBge52kFcA6YBuwuKUrcS7wVWA/4EbbqzqZd0RE7F5uKBUxDhnCil41WYewIiKiB6WAREREJSkgERFRSQpIRERUkgISERGVpIBEREQlKSAREVFJCkhERFSSAhIREZWkgERERCUpIBERUUkKSEREVJICEhERlaSAREREJSkgERFRSQpIRERU0tECIulySUOS1u7kuf8sabukF7e0LZG0XtL9kk5saZ8vaa2kn0j6bCdzjoiI9nS6B7IMOGl0o6RZwLuAjS1t84DTgHnAKcCl5T3QAb4AnG17LjBX0vP2GRER3dXRAmL7duDxnTz1GeDjo9pOBa6xPWx7A7AeWCBpAJhu+65yuyuARR1KOSIi2tT1ORBJC4FNtu8b9dRMYFPL+paybSawuaV9c9kWERE12rubwSTtD1xIMXzVMYODgzuWG40GjUajk+EiIqacZrNJs9nco33I9sRkM1Y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mO0jKCZJb7V9Rt151aEcntgkaW7ZdAL9e2DBg8CbJO0nSRSfRb8dUDC6R74SOLNc/iDQTz88n/NZSDqZYth7oe2n2t1JTxQQSccBHwDeIemecrz75LrziknhPOAqSfdSHIX1yZrzqYXtNRQ9sHuAf6T48vhSrUl1kaSrgX8A5kp6UNKHgIuAd0kaucLFRXXm2C1jfBZ/BRwI3FJ+f17a1r5yImFERFTREz2QiIjovhSQiIioJAUkIiIqSQGJiIhKUkAiIqKSFJCIiKgkBSQiIipJAYmIiEr+P71BWn/o4C2PAAAAAElFTkSuQmCC width=400 height=266 class=img_ev3q></p>
|
||
<p>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 <a href=https://en.wikipedia.org/wiki/Triangular_distribution target=_blank rel="noopener noreferrer">Triangle Distribution</a>, which is itself a special case of the <a href=https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution target=_blank rel="noopener noreferrer">Irwin-Hall Distribution</a>.</p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id=the-edge-cases>The Edge Cases<a href=#the-edge-cases class=hash-link aria-label="Direct link to The Edge Cases" title="Direct link to The Edge Cases"></a></h2>
|
||
<p>Given that we understand how the results of two fair dice are distributed, let's see some of the interesting edge cases that come up. This will give us assurance that when a casino is cheating, it is detectable (given sufficient data). To make this as hard as possible, we will think of scenarios where the expected value of the sum of loaded dice is the same as the expected value of the sum of fair dice.</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=edge-case-1>Edge Case 1<a href=#edge-case-1 class=hash-link aria-label="Direct link to Edge Case 1" title="Direct link to Edge Case 1"></a></h3>
|
||
<p>What happens when one die is biased low, and one die is biased high? That is, where:</p>
|
||
<span class=katex-display><span class=katex><span class=katex-mathml><math display=block><semantics><mtable rowspacing=0.25em columnalign=right columnspacing=""><mtr><mtd><mstyle scriptlevel=0 displaystyle=true><mtable rowspacing=0.16em columnalign="center center" columnspacing=1em><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><msub><mi>D</mi><mn>1</mn></msub><mo>=</mo><mrow><mo fence=true>{</mo><mtable rowspacing=0.16em columnalign="left right" columnspacing=1em><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>1</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>3</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>2</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>3</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>3</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>4</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>5</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>6</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr></mtable></mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><msub><mi>D</mi><mn>2</mn></msub><mo>=</mo><mrow><mo fence=true>{</mo><mtable rowspacing=0.16em columnalign="left right" columnspacing=1em><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>1</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>2</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>3</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>4</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>5</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>3</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>6</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>3</mn></mrow></mstyle></mtd></mtr></mtable></mrow></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi mathvariant=double-struck>E</mi><mo stretchy=false>[</mo><msub><mi>D</mi><mn>1</mn></msub><mo stretchy=false>]</mo><mo>=</mo><mn>2.5</mn></mrow></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi mathvariant=double-struck>E</mi><mo stretchy=false>[</mo><msub><mi>D</mi><mn>2</mn></msub><mo stretchy=false>]</mo><mo>=</mo><mn>4.5</mn></mrow></mstyle></mtd></mtr></mtable></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=true><mrow><mi mathvariant=double-struck>E</mi><mo stretchy=false>[</mo><msub><mi>D</mi><mn>1</mn></msub><mo>+</mo><msub><mi>D</mi><mn>2</mn></msub><mo stretchy=false>]</mo><mo>=</mo><mn>7</mn><mo>=</mo><mi mathvariant=double-struck>E</mi><mo stretchy=false>[</mo><msub><mi>D</mi><mrow><mi>f</mi><mi>a</mi><mi>i</mi><mi>r</mi></mrow></msub><mo>+</mo><msub><mi>D</mi><mrow><mi>f</mi><mi>a</mi><mi>i</mi><mi>r</mi></mrow></msub><mo stretchy=false>]</mo></mrow></mstyle></mtd></mtr></mtable><annotation encoding=application/x-tex>\begin{align*}
|
||
\begin{array}{cc}
|
||
D_1 = \left\{
|
||
\begin{array}{lr}
|
||
1 & w.p. 1/3\\
|
||
2 & w.p. 1/3\\
|
||
3 & w.p. 1/12\\
|
||
4 & w.p. 1/12\\
|
||
5 & w.p. 1/12\\
|
||
6 & w.p. 1/12
|
||
\end{array}
|
||
\right. &
|
||
D_2 = \left\{
|
||
\begin{array}{lr}
|
||
1 & w.p. 1/12\\
|
||
2 & w.p. 1/12\\
|
||
3 & w.p. 1/12\\
|
||
4 & w.p. 1/12\\
|
||
5 & w.p. 1/3\\
|
||
6 & w.p. 1/3
|
||
\end{array}
|
||
\right. \\
|
||
\mathbb{E}[D_1] = 2.5 & \mathbb{E}[D_2] = 4.5
|
||
\end{array}\\
|
||
\mathbb{E}[D_1 + D_2] = 7 = \mathbb{E}[D_{fair} + D_{fair}]
|
||
\end{align*}</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:10.2em;vertical-align:-4.85em></span><span class=mord><span class=mtable><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:5.35em><span style=top:-7.35em><span class=pstrut style=height:6.45em></span><span class=mord><span class=mord><span class=mtable><span class=arraycolsep style=width:0.5em></span><span class=col-align-c><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:4.45em><span style=top:-6.45em><span class=pstrut style=height:5.85em></span><span class=mord><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=minner><span class=mopen><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-1.366em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎩</span></span></span><span style=top:-1.358em><span class=pstrut style=height:3.816em></span><span style=height:1.816em;width:0.8889em><svg width=0.8889em height=1.816em style=width:0.8889em viewBox="0 0 888.89 1816" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1816 H384z M384 0 H504 V1816 H384z"/></svg></span></span><span style=top:-3.816em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎨</span></span></span><span style=top:-4.958em><span class=pstrut style=height:3.816em></span><span style=height:1.816em;width:0.8889em><svg width=0.8889em height=1.816em style=width:0.8889em viewBox="0 0 888.89 1816" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1816 H384z M384 0 H504 V1816 H384z"/></svg></span></span><span style=top:-6.766em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎧</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span></span><span class=mord><span class=mtable><span class=arraycolsep style=width:0.5em></span><span class=col-align-l><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-6.01em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>1</span></span></span><span style=top:-4.81em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>2</span></span></span><span style=top:-3.61em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>3</span></span></span><span style=top:-2.41em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>4</span></span></span><span style=top:-1.21em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>5</span></span></span><span style=top:-0.01em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>6</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span><span class=arraycolsep style=width:0.5em></span><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-6.01em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/3</span></span></span><span style=top:-4.81em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/3</span></span></span><span style=top:-3.61em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-2.41em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-1.21em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-0.01em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span></span></span><span class="mclose nulldelimiter"></span></span></span></span><span style=top:-2.26em><span class=pstrut style=height:5.85em></span><span class=mord><span class="mord mathbb">E</span><span class=mopen>[</span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mclose>]</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>2.5</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.95em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span><span class=arraycolsep style=width:0.5em></span><span class=col-align-c><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:4.45em><span style=top:-6.45em><span class=pstrut style=height:5.85em></span><span class=mord><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=minner><span class=mopen><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-1.366em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎩</span></span></span><span style=top:-1.358em><span class=pstrut style=height:3.816em></span><span style=height:1.816em;width:0.8889em><svg width=0.8889em height=1.816em style=width:0.8889em viewBox="0 0 888.89 1816" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1816 H384z M384 0 H504 V1816 H384z"/></svg></span></span><span style=top:-3.816em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎨</span></span></span><span style=top:-4.958em><span class=pstrut style=height:3.816em></span><span style=height:1.816em;width:0.8889em><svg width=0.8889em height=1.816em style=width:0.8889em viewBox="0 0 888.89 1816" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1816 H384z M384 0 H504 V1816 H384z"/></svg></span></span><span style=top:-6.766em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎧</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span></span><span class=mord><span class=mtable><span class=arraycolsep style=width:0.5em></span><span class=col-align-l><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-6.01em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>1</span></span></span><span style=top:-4.81em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>2</span></span></span><span style=top:-3.61em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>3</span></span></span><span style=top:-2.41em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>4</span></span></span><span style=top:-1.21em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>5</span></span></span><span style=top:-0.01em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>6</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span><span class=arraycolsep style=width:0.5em></span><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-6.01em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-4.81em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-3.61em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-2.41em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-1.21em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/3</span></span></span><span style=top:-0.01em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/3</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span></span></span><span class="mclose nulldelimiter"></span></span></span></span><span style=top:-2.26em><span class=pstrut style=height:5.85em></span><span class=mord><span class="mord mathbb">E</span><span class=mopen>[</span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mclose>]</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>4.5</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.95em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span></span></span></span></span><span style=top:-2.26em><span class=pstrut style=height:6.45em></span><span class=mord><span class="mord mathbb">E</span><span class=mopen>[</span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2222em></span><span class=mbin>+</span><span class=mspace style=margin-right:0.2222em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mclose>]</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>7</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class="mord mathbb">E</span><span class=mopen>[</span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3361em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style=margin-right:0.10764em>f</span><span class="mord mathnormal mtight">ai</span><span class="mord mathnormal mtight" style=margin-right:0.02778em>r</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.2861em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2222em></span><span class=mbin>+</span><span class=mspace style=margin-right:0.2222em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3361em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style=margin-right:0.10764em>f</span><span class="mord mathnormal mtight">ai</span><span class="mord mathnormal mtight" style=margin-right:0.02778em>r</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.2861em><span></span></span></span></span></span></span><span class=mclose>]</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:4.85em><span></span></span></span></span></span></span></span></span></span></span></span>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token keyword" style="color:hsl(301, 63%, 40%)">def</span><span class="token plain"> </span><span class="token function" style="color:hsl(221, 87%, 60%)">unfair_die</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">p_vals</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> n</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> x </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">random</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">multinomial</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> p_vals</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> n</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">return</span><span class="token plain"> x</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">nonzero</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token plain"> </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">d1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">x1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> unfair_die</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">10000</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">x2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> unfair_die</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">10000</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">pd</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">Series</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">x1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+</span><span class="token plain"> x2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">plot</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">kind</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token string" style="color:hsl(119, 34%, 47%)">'hist'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> bins</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">11</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">;</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">title</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token string" style="color:hsl(119, 34%, 47%)">'$D_1$ biased low, $D_2$ biased high'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">;</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p><img decoding=async loading=lazy alt=png src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAEMCAYAAADqG+D0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAG2RJREFUeJzt3X20XXV95/H3ByJP8lB8gKsJTz6EBlrEIPGBihetgG150I4RdRURdLkUBWtnRsJ0hminU+laiFgLqz5hYMAIKAothZAFV8ZpNRRJQZKBVA0QMBcfEEVYmJDP/LF/lxxubpJzd7LPvvecz2uts7LP7+y9f9+zc8/5nt/D3lu2iYiImKwd2g4gIiKmpySQiIioJQkkI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rOaa2rAEetP1v5fk1VAllEP0h8CPbv7D9NPAN4HUtx9S2UUn7AkgaAh5pOZ5WSTqNquu76x8WfZNAgC8DK2xf1HYgbbJ9ru39bb+EapD0Ftunth1XG0r3xIOSZpeiNzG4EwseAF4jaRdJojoWgzahYHyL/DrgtLL8HmCQfng+61hIOp6q2/tE2091u5O+SCCSjgLeDbxR0p2lv/v4tuOKKeEs4ApJy6lmYf2vluNphe1lVC2wO4F/p/ry+HyrQfWQpCuBfwFmS3pA0nuBTwFvljR2hYtPtRljr2zmWPwdsDtwc/n+vLirfeVEwoiIqKMvWiAREdF7SSAREVFLEkhERNSSBBIREbUkgURERC1JIBERUUsSSERE1JIEEhERtfx/t8CCaUQXJ5cAAAAASUVORK5CYII=" width=400 height=268 class=img_ev3q></p>
|
||
<p>We can see that while the 7 value remains the most likely (as expected), the distribution is not so nicely shaped any more.</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=edge-case-2>Edge Case 2<a href=#edge-case-2 class=hash-link aria-label="Direct link to Edge Case 2" title="Direct link to Edge Case 2"></a></h3>
|
||
<p>When one die is loaded low, and one is loaded high, we've seen how we can detect them. How about when two die are loaded both low and high? That is, we have the following distribution:</p>
|
||
<span class=katex-display><span class=katex><span class=katex-mathml><math display=block><semantics><mtable rowspacing=0.25em columnalign=right columnspacing=""><mtr><mtd><mstyle scriptlevel=0 displaystyle=true><mtable rowspacing=0.16em columnalign="center center" columnspacing=1em><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><msub><mi>D</mi><mn>1</mn></msub><mo>=</mo><mrow><mo fence=true>{</mo><mtable rowspacing=0.16em columnalign="left right" columnspacing=1em><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>1</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>3</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>2</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>3</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>4</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>5</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>6</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>3</mn></mrow></mstyle></mtd></mtr></mtable></mrow></mrow></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><msub><mi>D</mi><mn>2</mn></msub><mo>=</mo><mrow><mo fence=true>{</mo><mtable rowspacing=0.16em columnalign="left right" columnspacing=1em><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>1</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>3</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>2</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>3</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>4</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>5</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>12</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mn>6</mn></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>w</mi><mi mathvariant=normal>.</mi><mi>p</mi><mi mathvariant=normal>.</mi><mn>1</mn><mi mathvariant=normal>/</mi><mn>3</mn></mrow></mstyle></mtd></mtr></mtable></mrow></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi mathvariant=double-struck>E</mi><mo stretchy=false>[</mo><msub><mi>D</mi><mn>1</mn></msub><mo stretchy=false>]</mo><mo>=</mo><mn>3.5</mn></mrow></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi mathvariant=double-struck>E</mi><mo stretchy=false>[</mo><msub><mi>D</mi><mn>2</mn></msub><mo stretchy=false>]</mo><mo>=</mo><mn>3.5</mn></mrow></mstyle></mtd></mtr></mtable></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=true><mrow><mi mathvariant=double-struck>E</mi><mo stretchy=false>[</mo><msub><mi>D</mi><mn>1</mn></msub><mo>+</mo><msub><mi>D</mi><mn>2</mn></msub><mo stretchy=false>]</mo><mo>=</mo><mn>7</mn><mo>=</mo><mi mathvariant=double-struck>E</mi><mo stretchy=false>[</mo><msub><mi>D</mi><mrow><mi>f</mi><mi>a</mi><mi>i</mi><mi>r</mi></mrow></msub><mo>+</mo><msub><mi>D</mi><mrow><mi>f</mi><mi>a</mi><mi>i</mi><mi>r</mi></mrow></msub><mo stretchy=false>]</mo></mrow></mstyle></mtd></mtr></mtable><annotation encoding=application/x-tex>\begin{align*}
|
||
\begin{array}{cc}
|
||
D_1 = \left\{
|
||
\begin{array}{lr}
|
||
1 & w.p. 1/3\\
|
||
2 & w.p. 1/12\\
|
||
3 & w.p. 1/12\\
|
||
4 & w.p. 1/12\\
|
||
5 & w.p. 1/12\\
|
||
6 & w.p. 1/3
|
||
\end{array}
|
||
\right. &
|
||
D_2 = \left\{
|
||
\begin{array}{lr}
|
||
1 & w.p. 1/3\\
|
||
2 & w.p. 1/12\\
|
||
3 & w.p. 1/12\\
|
||
4 & w.p. 1/12\\
|
||
5 & w.p. 1/12\\
|
||
6 & w.p. 1/3
|
||
\end{array}
|
||
\right. \\
|
||
\mathbb{E}[D_1] = 3.5 & \mathbb{E}[D_2] = 3.5
|
||
\end{array}\\
|
||
\mathbb{E}[D_1 + D_2] = 7 = \mathbb{E}[D_{fair} + D_{fair}]
|
||
\end{align*}</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:10.2em;vertical-align:-4.85em></span><span class=mord><span class=mtable><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:5.35em><span style=top:-7.35em><span class=pstrut style=height:6.45em></span><span class=mord><span class=mord><span class=mtable><span class=arraycolsep style=width:0.5em></span><span class=col-align-c><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:4.45em><span style=top:-6.45em><span class=pstrut style=height:5.85em></span><span class=mord><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=minner><span class=mopen><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-1.366em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎩</span></span></span><span style=top:-1.358em><span class=pstrut style=height:3.816em></span><span style=height:1.816em;width:0.8889em><svg width=0.8889em height=1.816em style=width:0.8889em viewBox="0 0 888.89 1816" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1816 H384z M384 0 H504 V1816 H384z"/></svg></span></span><span style=top:-3.816em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎨</span></span></span><span style=top:-4.958em><span class=pstrut style=height:3.816em></span><span style=height:1.816em;width:0.8889em><svg width=0.8889em height=1.816em style=width:0.8889em viewBox="0 0 888.89 1816" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1816 H384z M384 0 H504 V1816 H384z"/></svg></span></span><span style=top:-6.766em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎧</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span></span><span class=mord><span class=mtable><span class=arraycolsep style=width:0.5em></span><span class=col-align-l><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-6.01em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>1</span></span></span><span style=top:-4.81em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>2</span></span></span><span style=top:-3.61em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>3</span></span></span><span style=top:-2.41em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>4</span></span></span><span style=top:-1.21em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>5</span></span></span><span style=top:-0.01em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>6</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span><span class=arraycolsep style=width:0.5em></span><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-6.01em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/3</span></span></span><span style=top:-4.81em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-3.61em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-2.41em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-1.21em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-0.01em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/3</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span></span></span><span class="mclose nulldelimiter"></span></span></span></span><span style=top:-2.26em><span class=pstrut style=height:5.85em></span><span class=mord><span class="mord mathbb">E</span><span class=mopen>[</span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mclose>]</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>3.5</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.95em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span><span class=arraycolsep style=width:0.5em></span><span class=col-align-c><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:4.45em><span style=top:-6.45em><span class=pstrut style=height:5.85em></span><span class=mord><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=minner><span class=mopen><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-1.366em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎩</span></span></span><span style=top:-1.358em><span class=pstrut style=height:3.816em></span><span style=height:1.816em;width:0.8889em><svg width=0.8889em height=1.816em style=width:0.8889em viewBox="0 0 888.89 1816" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1816 H384z M384 0 H504 V1816 H384z"/></svg></span></span><span style=top:-3.816em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎨</span></span></span><span style=top:-4.958em><span class=pstrut style=height:3.816em></span><span style=height:1.816em;width:0.8889em><svg width=0.8889em height=1.816em style=width:0.8889em viewBox="0 0 888.89 1816" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1816 H384z M384 0 H504 V1816 H384z"/></svg></span></span><span style=top:-6.766em><span class=pstrut style=height:3.816em></span><span class="delimsizinginner delim-size4"><span>⎧</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span></span><span class=mord><span class=mtable><span class=arraycolsep style=width:0.5em></span><span class=col-align-l><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-6.01em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>1</span></span></span><span style=top:-4.81em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>2</span></span></span><span style=top:-3.61em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>3</span></span></span><span style=top:-2.41em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>4</span></span></span><span style=top:-1.21em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>5</span></span></span><span style=top:-0.01em><span class=pstrut style=height:3em></span><span class=mord><span class=mord>6</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span><span class=arraycolsep style=width:0.5em></span><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.85em><span style=top:-6.01em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/3</span></span></span><span style=top:-4.81em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-3.61em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-2.41em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-1.21em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/12</span></span></span><span style=top:-0.01em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02691em>w</span><span class=mord>.</span><span class="mord mathnormal">p</span><span class=mord>.1/3</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.35em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span></span></span><span class="mclose nulldelimiter"></span></span></span></span><span style=top:-2.26em><span class=pstrut style=height:5.85em></span><span class=mord><span class="mord mathbb">E</span><span class=mopen>[</span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mclose>]</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>3.5</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:3.95em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span></span></span></span></span><span style=top:-2.26em><span class=pstrut style=height:6.45em></span><span class=mord><span class="mord mathbb">E</span><span class=mopen>[</span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">1</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2222em></span><span class=mbin>+</span><span class=mspace style=margin-right:0.2222em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mclose>]</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>7</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class="mord mathbb">E</span><span class=mopen>[</span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3361em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style=margin-right:0.10764em>f</span><span class="mord mathnormal mtight">ai</span><span class="mord mathnormal mtight" style=margin-right:0.02778em>r</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.2861em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2222em></span><span class=mbin>+</span><span class=mspace style=margin-right:0.2222em></span><span class=mord><span class="mord mathnormal" style=margin-right:0.02778em>D</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3361em><span style=top:-2.55em;margin-left:-0.0278em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style=margin-right:0.10764em>f</span><span class="mord mathnormal mtight">ai</span><span class="mord mathnormal mtight" style=margin-right:0.02778em>r</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.2861em><span></span></span></span></span></span></span><span class=mclose>]</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:4.85em><span></span></span></span></span></span></span></span></span></span></span></span>
|
||
<p>We can see even that the expected value of each individual die is the same as the fair die! However, the distribution (if we are doing this correctly) should still be skewed:</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">d1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> d1</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">x1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> unfair_die</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">10000</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">x2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> unfair_die</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">10000</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">pd</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">Series</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">x1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+</span><span class="token plain"> x2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">plot</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">kind</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token string" style="color:hsl(119, 34%, 47%)">'hist'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> bins</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">11</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">title</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token string" style="color:hsl(119, 34%, 47%)">"$D_1$ and $D_2$ biased to 1 and 6"</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">;</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p><img decoding=async loading=lazy alt=png src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAZAAAAEMCAYAAADqG+D0AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAGuhJREFUeJzt3X2UXXV97/H3ByIC8lAskmCigNUg4ANGDSrLdkB50CqgvSLiKuLTcikCVXsvhNpL7JPStRTQXlxVEQMXmgv4BJZCYOHUZXslEUGQ5EJaDZBABhVEKQgJ+dw/9m/gOJmHM3uyz54583mtdVb2+Z398N1nJvM5v9/eZ2/ZJiIiYrK2a7uAiIiYmRIgERFRSwIkIiJqSYBEREQtCZCIiKglARIREbUkQCIiopYESMw4ki6S9Fc92M7PJB0+zus/kfSHTdfRsb2e7Hev9et+zQYJkIiabL/E9vfarmPYRIHXx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kW6nOwvq7lutphe2VVD2wW4AfU/3x+FKrRfWQpMuAfwcWSrpH0nuBzwBHSBq+wsVn2qyxV8Z4L74A7AJcX/5+XtDVuvJFwoiIqKMveiAREdF7CZCIiKglARIREbUkQCIiopYESERE1JIAiYiIWhIgERFRSwIkIiJq+f8KwJfCiHKoPQAAAABJRU5ErkJggg==" width=400 height=268 class=img_ev3q></p>
|
||
<p>In a very un-subtle way, we have of course made the values 2 and 12 far more likely.</p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id=detection-conclusion>Detection Conclusion<a href=#detection-conclusion class=hash-link aria-label="Direct link to Detection Conclusion" title="Direct link to Detection Conclusion"></a></h2>
|
||
<p>There are some trivial examples of cheating that are easy to detect: whenever the expected value of the sum of two fair dice deviates from the expected value for the sum of two fair dice, we can immediately conclude that there is cheating at stake.</p>
|
||
<p>The interesting edge cases occur when the expected value of the sum of loaded dice matches the expected value of the sum of fair dice. Considering the above examples (and a couple more I ran through in developing this), we have seen that in every circumstance having two unfair dice leads to a distribution of results different from the fair results.</p>
|
||
<p>We can thus finally state: <strong>just by looking at the distribution of results from this game, we can immediately conclude whether there is cheating.</strong></p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id=simulated-annealing>Simulated Annealing<a href=#simulated-annealing class=hash-link aria-label="Direct link to Simulated Annealing" title="Direct link to Simulated Annealing"></a></h2>
|
||
<p>What we really would like to do though, is see if there is any way to determine how exactly the dice are loaded. This is significantly more complicated, but we can borrow some algorithms from Machine Learning to figure out exactly how to perform this process. I'm using the Simulated Annealing algorithm, and I discuss why this works and why I chose it over some of the alternatives in the <a href=#Justification-of-Simulated-Annealing>justification</a>. If you don't care about how I set up the model and just want to see the code, check out <a href=#The-actual-code>the actual code</a>.</p>
|
||
<p><a href=https://en.wikipedia.org/wiki/Simulated_annealing target=_blank rel="noopener noreferrer">Simulated Annealing</a> is a variation of the <a href=https://en.wikipedia.org/wiki/Metropolis%E2%80%93Hastings_algorithm target=_blank rel="noopener noreferrer">Metropolis-Hastings Algorithm</a>, but the important thing for us is: Simulated Annealing allows us to quickly optimize high-dimensional problems. But what exactly are we trying to optimize? Ideally, we want a function that can tell us whether one distribution for the dice better explains the results than another distribution. This is known as the <strong>likelihood</strong> function.</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=deriving-the-likelihood-function>Deriving the Likelihood function<a href=#deriving-the-likelihood-function class=hash-link aria-label="Direct link to Deriving the Likelihood function" title="Direct link to Deriving the Likelihood function"></a></h3>
|
||
<p>To derive our likelihood function, we want to know: <strong>what is the probability of seeing a specific result given those hidden parameters?</strong> This is actually a surprisingly difficult problem. While we can do a lot of calculations by hand, we need a more general solution since we will be working with very some interesting die distributions.</p>
|
||
<p>We first note that the sum of two dice can take on 11 different values - 2 through 12. This implies that each individual sum follows a <a href=https://en.wikipedia.org/wiki/Categorical_distribution target=_blank rel="noopener noreferrer">Categorical distribution</a>. That is:</p>
|
||
<span class=katex-display><span class=katex><span class=katex-mathml><math display=block><semantics><mtable rowspacing=0.25em columnalign=right columnspacing=""><mtr><mtd><mstyle scriptlevel=0 displaystyle=true><mrow><mrow><mi mathvariant=script>L</mi><mo stretchy=false>(</mo><mi mathvariant=script>x</mi><mo stretchy=false>)</mo></mrow><mo>=</mo><mrow><mo fence=true>{</mo><mtable rowspacing=0.16em columnalign="left right" columnspacing=1em><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><msub><mi>p</mi><mn>2</mn></msub></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>x</mi><mo>=</mo><mn>2</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><msub><mi>p</mi><mn>3</mn></msub></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>x</mi><mo>=</mo><mn>3</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><mo lspace=0em rspace=0em>…</mo></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow/></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><msub><mi>p</mi><mn>11</mn></msub></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>x</mi><mo>=</mo><mn>11</mn></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel=0 displaystyle=false><msub><mi>p</mi><mn>12</mn></msub></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=false><mrow><mi>x</mi><mo>=</mo><mn>12</mn></mrow></mstyle></mtd></mtr></mtable></mrow></mrow></mstyle></mtd></mtr></mtable><annotation encoding=application/x-tex>\begin{align*}
|
||
\mathcal{L(x)} = \left\{
|
||
\begin{array}{lr}
|
||
p_2 & x = 2\\
|
||
p_3 & x = 3\\
|
||
\ldots & \\
|
||
p_{11} & x = 11\\
|
||
p_{12} & x = 12
|
||
\end{array}
|
||
\right.
|
||
\end{align*}</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:6.3em;vertical-align:-2.9em></span><span class=mord><span class=mtable><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.4em><span style=top:-5.4em><span class=pstrut style=height:5.25em></span><span class=mord><span class=mord><span class="mord mathcal">L</span><span class=mopen>(</span><span class="mord mathnormal">x</span><span class=mclose>)</span></span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=minner><span class=mopen><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.25em><span style=top:-1.366em><span class=pstrut style=height:3.216em></span><span class="delimsizinginner delim-size4"><span>⎩</span></span></span><span style=top:-1.358em><span class=pstrut style=height:3.216em></span><span style=height:1.216em;width:0.8889em><svg width=0.8889em height=1.216em style=width:0.8889em viewBox="0 0 888.89 1216" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1216 H384z M384 0 H504 V1216 H384z"/></svg></span></span><span style=top:-3.216em><span class=pstrut style=height:3.216em></span><span class="delimsizinginner delim-size4"><span>⎨</span></span></span><span style=top:-4.358em><span class=pstrut style=height:3.216em></span><span style=height:1.216em;width:0.8889em><svg width=0.8889em height=1.216em style=width:0.8889em viewBox="0 0 888.89 1216" preserveAspectRatio=xMinYMin><path d="M384 0 H504 V1216 H384z M384 0 H504 V1216 H384z"/></svg></span></span><span style=top:-5.566em><span class=pstrut style=height:3.216em></span><span class="delimsizinginner delim-size4"><span>⎧</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:2.75em><span></span></span></span></span></span></span><span class=mord><span class=mtable><span class=arraycolsep style=width:0.5em></span><span class=col-align-l><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.25em><span style=top:-5.41em><span class=pstrut style=height:3em></span><span class=mord><span class=mord><span class="mord mathnormal">p</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:0em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">2</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span></span></span><span style=top:-4.21em><span class=pstrut style=height:3em></span><span class=mord><span class=mord><span class="mord mathnormal">p</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:0em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight">3</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span></span></span><span style=top:-3.01em><span class=pstrut style=height:3em></span><span class=mord><span class=minner>…</span></span></span><span style=top:-1.81em><span class=pstrut style=height:3em></span><span class=mord><span class=mord><span class="mord mathnormal">p</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:0em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">11</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span></span></span><span style=top:-0.61em><span class=pstrut style=height:3em></span><span class=mord><span class=mord><span class="mord mathnormal">p</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3011em><span style=top:-2.55em;margin-left:0em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">12</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:2.75em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span><span class=arraycolsep style=width:0.5em></span><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:3.25em><span style=top:-5.41em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal">x</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>2</span></span></span><span style=top:-4.21em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal">x</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>3</span></span></span><span style=top:-3.01em><span class=pstrut style=height:3em></span><span class=mord></span></span><span style=top:-1.81em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal">x</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>11</span></span></span><span style=top:-0.61em><span class=pstrut style=height:3em></span><span class=mord><span class="mord mathnormal">x</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class=mord>12</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:2.75em><span></span></span></span></span></span><span class=arraycolsep style=width:0.5em></span></span></span><span class="mclose nulldelimiter"></span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:2.9em><span></span></span></span></span></span></span></span></span></span></span></span>
|
||
<p>Where each <span class=katex><span class=katex-mathml><math><semantics><mrow><msub><mi>p</mi><mi>i</mi></msub></mrow><annotation encoding=application/x-tex>p_i</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:0.625em;vertical-align:-0.1944em></span><span class=mord><span class="mord mathnormal">p</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3117em><span style=top:-2.55em;margin-left:0em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">i</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span></span></span></span> is the probability of seeing that specific result. However, we need to calculate what each probability is! I'll save you the details, but <a href=http://math.stackexchange.com/a/1646360/320784 target=_blank rel="noopener noreferrer">this author</a> explains how to do it.</p>
|
||
<p>Now, we would like to know the likelihood of our entire data-set. This is trivial:</p>
|
||
<span class=katex-display><span class=katex><span class=katex-mathml><math display=block><semantics><mtable rowspacing=0.25em columnalign="right left" columnspacing=0em><mtr><mtd><mstyle scriptlevel=0 displaystyle=true><mrow><mi mathvariant=script>L</mi><mo stretchy=false>(</mo><mi mathvariant=bold>X</mi><mo stretchy=false>)</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=true><mrow><mrow/><mo>=</mo><munderover><mo>∏</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><mi>L</mi><mo stretchy=false>(</mo><mi>x</mi><mo stretchy=false>)</mo></mrow></mstyle></mtd></mtr></mtable><annotation encoding=application/x-tex>\begin{align*}
|
||
\mathcal{L(\mathbf{X})} &= \prod_{i=1}^n L(x)
|
||
\end{align*}</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:3.2291em;vertical-align:-1.3645em></span><span class=mord><span class=mtable><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:1.8645em><span style=top:-3.8645em><span class=pstrut style=height:3.6514em></span><span class=mord><span class=mord><span class="mord mathcal">L</span><span class=mopen>(</span><span class="mord mathbf">X</span><span class=mclose>)</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:1.3645em><span></span></span></span></span></span><span class=col-align-l><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:1.8645em><span style=top:-3.8645em><span class=pstrut style=height:3.6514em></span><span class=mord><span class=mord></span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:1.6514em><span style=top:-1.8723em;margin-left:0em><span class=pstrut style=height:3.05em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mrel mtight">=</span><span class="mord mtight">1</span></span></span></span><span style=top:-3.05em><span class=pstrut style=height:3.05em></span><span><span class="mop op-symbol large-op">∏</span></span></span><span style=top:-4.3em;margin-left:0em><span class=pstrut style=height:3.05em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:1.2777em><span></span></span></span></span></span><span class=mspace style=margin-right:0.1667em></span><span class="mord mathnormal">L</span><span class=mopen>(</span><span class="mord mathnormal">x</span><span class=mclose>)</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:1.3645em><span></span></span></span></span></span></span></span></span></span></span></span>
|
||
<p>However, it's typically much easier to work with the <span class=katex><span class=katex-mathml><math><semantics><mrow><mi>log</mi><mo></mo><mo stretchy=false>(</mo><mi mathvariant=script>L</mi><mo stretchy=false>)</mo></mrow><annotation encoding=application/x-tex>\log(\mathcal{L})</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:1em;vertical-align:-0.25em></span><span class=mop>lo<span style=margin-right:0.01389em>g</span></span><span class=mopen>(</span><span class="mord mathcal">L</span><span class=mclose>)</span></span></span></span> function instead. This is critically important from a computational perspective: when you multiply so many small numbers together (i.e. the product of <span class=katex><span class=katex-mathml><math><semantics><mrow><mi>L</mi><mo stretchy=false>(</mo><mi>x</mi><mo stretchy=false>)</mo></mrow><annotation encoding=application/x-tex>L(x)</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:1em;vertical-align:-0.25em></span><span class="mord mathnormal">L</span><span class=mopen>(</span><span class="mord mathnormal">x</span><span class=mclose>)</span></span></span></span> terms) the computer suffers from rounding error; if we don't control for this, we will find that no matter the distributions we choose for each die, the "likelihood" will be close to zero because the computer is not precise enough.</p>
|
||
<span class=katex-display><span class=katex><span class=katex-mathml><math display=block><semantics><mtable rowspacing=0.25em columnalign="right left" columnspacing=0em><mtr><mtd><mstyle scriptlevel=0 displaystyle=true><mrow><mi>log</mi><mo></mo><mo stretchy=false>(</mo><mi mathvariant=script>L</mi><mo stretchy=false>)</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel=0 displaystyle=true><mrow><mrow/><mo>=</mo><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>n</mi></munderover><mi>log</mi><mo></mo><mo stretchy=false>(</mo><mi>L</mi><mo stretchy=false>)</mo></mrow></mstyle></mtd></mtr></mtable><annotation encoding=application/x-tex>\begin{align*}
|
||
\log(\mathcal{L}) &= \sum_{i=1}^n \log(L)
|
||
\end{align*}</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:3.2291em;vertical-align:-1.3645em></span><span class=mord><span class=mtable><span class=col-align-r><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:1.8645em><span style=top:-3.8645em><span class=pstrut style=height:3.6514em></span><span class=mord><span class=mop>lo<span style=margin-right:0.01389em>g</span></span><span class=mopen>(</span><span class="mord mathcal">L</span><span class=mclose>)</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:1.3645em><span></span></span></span></span></span><span class=col-align-l><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:1.8645em><span style=top:-3.8645em><span class=pstrut style=height:3.6514em></span><span class=mord><span class=mord></span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>=</span><span class=mspace style=margin-right:0.2778em></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:1.6514em><span style=top:-1.8723em;margin-left:0em><span class=pstrut style=height:3.05em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">i</span><span class="mrel mtight">=</span><span class="mord mtight">1</span></span></span></span><span style=top:-3.05em><span class=pstrut style=height:3.05em></span><span><span class="mop op-symbol large-op">∑</span></span></span><span style=top:-4.3em;margin-left:0em><span class=pstrut style=height:3.05em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight">n</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:1.2777em><span></span></span></span></span></span><span class=mspace style=margin-right:0.1667em></span><span class=mop>lo<span style=margin-right:0.01389em>g</span></span><span class=mopen>(</span><span class="mord mathnormal">L</span><span class=mclose>)</span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:1.3645em><span></span></span></span></span></span></span></span></span></span></span></span>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=the-process-of-simulated-annealing>The process of Simulated Annealing<a href=#the-process-of-simulated-annealing class=hash-link aria-label="Direct link to The process of Simulated Annealing" title="Direct link to The process of Simulated Annealing"></a></h3>
|
||
<p>The means by which we optimize our likelihood function is the simulated annealing algorithm. The way it works is as follows:</p>
|
||
<ol>
|
||
<li>
|
||
<p>Start with a random guess for the parameters we are trying to optimize. In our case we are trying to guess the distribution of two dice, and so we "optimize" until we have a distribution that matches the data.</p>
|
||
</li>
|
||
<li>
|
||
<p>For each iteration of the algorithm:</p>
|
||
<ol>
|
||
<li>Generate a new "proposed" set of parameters based on the current parameters -
|
||
i.e. slightly modify the current parameters to get a new set of parameters.</li>
|
||
<li>Calculate the value of <span class=katex><span class=katex-mathml><math><semantics><mrow><mi>log</mi><mo></mo><mo stretchy=false>(</mo><mi mathvariant=script>L</mi><mo stretchy=false>)</mo></mrow><annotation encoding=application/x-tex>\log(\mathcal{L})</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:1em;vertical-align:-0.25em></span><span class=mop>lo<span style=margin-right:0.01389em>g</span></span><span class=mopen>(</span><span class="mord mathcal">L</span><span class=mclose>)</span></span></span></span> for each set of parameters. If the function value for the
|
||
proposed parameter set is higher than for the current, automatically switch to the new parameter set
|
||
and continue the next iteration.</li>
|
||
<li>Given the new parameter set performs worse, determine a probability of switching to the new parameter set anyways: <span class=katex><span class=katex-mathml><math><semantics><mrow><mi mathvariant=script>P</mi><mo stretchy=false>(</mo><msub><mi>p</mi><mrow><mi>c</mi><mi>u</mi><mi>r</mi><mi>r</mi><mi>e</mi><mi>n</mi><mi>t</mi></mrow></msub><mo separator=true>,</mo><msub><mi>p</mi><mrow><mi>p</mi><mi>r</mi><mi>o</mi><mi>p</mi><mi>o</mi><mi>s</mi><mi>e</mi><mi>d</mi></mrow></msub><mo stretchy=false>)</mo></mrow><annotation encoding=application/x-tex>\mathcal{P}(p_{current}, p_{proposed})</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:1.0361em;vertical-align:-0.2861em></span><span class="mord mathcal" style=margin-right:0.08222em>P</span><span class=mopen>(</span><span class=mord><span class="mord mathnormal">p</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.2806em><span style=top:-2.55em;margin-left:0em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">c</span><span class="mord mathnormal mtight">u</span><span class="mord mathnormal mtight">rre</span><span class="mord mathnormal mtight">n</span><span class="mord mathnormal mtight">t</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.15em><span></span></span></span></span></span></span><span class=mpunct>,</span><span class=mspace style=margin-right:0.1667em></span><span class=mord><span class="mord mathnormal">p</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3361em><span style=top:-2.55em;margin-left:0em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight">ro</span><span class="mord mathnormal mtight">p</span><span class="mord mathnormal mtight">ose</span><span class="mord mathnormal mtight">d</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.2861em><span></span></span></span></span></span></span><span class=mclose>)</span></span></span></span></li>
|
||
<li>Switch to the new parameter set with probability <span class=katex><span class=katex-mathml><math><semantics><mrow><mi mathvariant=script>P</mi></mrow><annotation encoding=application/x-tex>\mathcal{P}</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:0.6833em></span><span class="mord mathcal" style=margin-right:0.08222em>P</span></span></span></span>. If you fail to switch, begin the next iteration.</li>
|
||
</ol>
|
||
</li>
|
||
<li>
|
||
<p>The algorithm is complete after we fail to make a transition <span class=katex><span class=katex-mathml><math><semantics><mrow><mi>n</mi></mrow><annotation encoding=application/x-tex>n</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:0.4306em></span><span class="mord mathnormal">n</span></span></span></span> times in a row.</p>
|
||
</li>
|
||
</ol>
|
||
<p>If everything goes according to plan, we will have a value that is close to the true distribution of each die.</p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id=the-actual-code>The actual code<a href=#the-actual-code class=hash-link aria-label="Direct link to The actual code" title="Direct link to The actual code"></a></h2>
|
||
<p>We start by defining the score function. This will tell us how well the proposed die densities actually explain the results.</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token keyword" style="color:hsl(301, 63%, 40%)">import</span><span class="token plain"> numpy </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">as</span><span class="token plain"> np</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"></span><span class="token keyword" style="color:hsl(301, 63%, 40%)">from</span><span class="token plain"> numpy </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">import</span><span class="token plain"> polynomial</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"></span><span class="token keyword" style="color:hsl(301, 63%, 40%)">def</span><span class="token plain"> </span><span class="token function" style="color:hsl(221, 87%, 60%)">density_coef</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d2_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># Calculating the probabilities of each outcome was taken</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># from this author: http://math.stackexchange.com/a/1710392/320784</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> d1_p </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> polynomial</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">Polynomial</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> d2_p </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> polynomial</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">Polynomial</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d2_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> coefs </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_p </span><span class="token operator" style="color:hsl(221, 87%, 60%)">*</span><span class="token plain"> d2_p</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">coef</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">return</span><span class="token plain"> coefs</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"></span><span class="token keyword" style="color:hsl(301, 63%, 40%)">def</span><span class="token plain"> </span><span class="token function" style="color:hsl(221, 87%, 60%)">score</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">x</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d1_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d2_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># We've now got the probabilities of each event, but we need</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># to shift the array a bit so we can use the x values to actually</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># index into it. This will allow us to do all the calculations</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># incredibly quickly</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> coefs </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> density_coef</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d2_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> coefs </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">hstack</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> coefs</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">return</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">log</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">coefs</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token plain">x</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token builtin" style="color:hsl(119, 34%, 47%)">sum</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p>Afterward, we need to write something to permute the proposal densities. We make random modifications, and eventually the best one survives.</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token keyword" style="color:hsl(301, 63%, 40%)">def</span><span class="token plain"> </span><span class="token function" style="color:hsl(221, 87%, 60%)">permute</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d2_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># To ensure we have legitimate densities, we will randomly</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># increase one die face probability by `change`,</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># and decrease one by `change`.</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># This means there are something less than (1/`change`)^12 possibilities</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># we are trying to search over.</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> change </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">.01</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> d1_index1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d1_index2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">random</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">randint</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> d2_index1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d2_index2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">random</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">randint</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># Also make sure to copy. I've had some weird aliasing issues</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># in the past that made everything blow up.</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> new_d1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">float64</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">copy</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> new_d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">float64</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">copy</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d2_density</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># While this doesn't account for the possibility that some</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># values go negative, in practice this never happens</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> new_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token plain">d1_index1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token plain"> </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+=</span><span class="token plain"> change</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> new_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token plain">d1_index2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token plain"> </span><span class="token operator" style="color:hsl(221, 87%, 60%)">-=</span><span class="token plain"> change</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> new_d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token plain">d2_index1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token plain"> </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+=</span><span class="token plain"> change</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> new_d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token plain">d2_index2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token plain"> </span><span class="token operator" style="color:hsl(221, 87%, 60%)">-=</span><span class="token plain"> change</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">return</span><span class="token plain"> new_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> new_d2</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p>Now we've got the main algorithm code to do. This is what brings all the pieces together.</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token keyword" style="color:hsl(301, 63%, 40%)">def</span><span class="token plain"> </span><span class="token function" style="color:hsl(221, 87%, 60%)">optimize</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">data</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> conv_count</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">10</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> max_iter</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">1e4</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> switch_failures </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> iter_count </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># Start with guessing fair dice</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_d1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">repeat</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">repeat</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> score</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">data</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> cur_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> cur_d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># Keep track of our best guesses - may not be</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># what we end with</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> max_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> cur_score</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> max_d1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> cur_d1</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> max_d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> cur_d2</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># Optimization stops when we have failed to switch `conv_count`</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># times (presumably because we have a great guess), or we reach</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># the maximum number of iterations.</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">while</span><span class="token plain"> switch_failures </span><span class="token operator" style="color:hsl(221, 87%, 60%)"><</span><span class="token plain"> conv_count </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">and</span><span class="token plain"> iter_count </span><span class="token operator" style="color:hsl(221, 87%, 60%)"><</span><span class="token plain"> max_iter</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> iter_count </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+=</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">if</span><span class="token plain"> iter_count </span><span class="token operator" style="color:hsl(221, 87%, 60%)">%</span><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">max_iter </span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">10</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"> </span><span class="token operator" style="color:hsl(221, 87%, 60%)">==</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">print</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token string" style="color:hsl(119, 34%, 47%)">'Iteration: {}; Current score (higher is better): {}'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token builtin" style="color:hsl(119, 34%, 47%)">format</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> iter_count</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> cur_score</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> new_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> new_d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> permute</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">cur_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> cur_d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> new_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> score</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">data</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> new_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> new_d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">if</span><span class="token plain"> new_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">></span><span class="token plain"> max_score</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> max_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_score</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> max_d1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_d1</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> max_d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_d2</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">if</span><span class="token plain"> new_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">></span><span class="token plain"> cur_score</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># If the new permutation beats the old one,</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># automatically select it.</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_score</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_d1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_d1</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_d2</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> switch_failures </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">else</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># We didn't beat the current score, but allow</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># for possibly switching anyways.</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> accept_prob </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">exp</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">new_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">-</span><span class="token plain"> cur_score</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> coin_toss </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">random</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">rand</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">if</span><span class="token plain"> coin_toss </span><span class="token operator" style="color:hsl(221, 87%, 60%)"><</span><span class="token plain"> accept_prob</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># We randomly switch to the new distribution</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_score </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_score</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_d1 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_d1</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> cur_d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> new_d2</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> switch_failures </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">0</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">else</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> switch_failures </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+=</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token comment" style="color:hsl(230, 4%, 64%)"># Return both our best guess, and the ending guess</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">return</span><span class="token plain"> max_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> max_d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> cur_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> cur_d2</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p>And now we have finished the hard work!</p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id=catching-the-casino>Catching the Casino<a href=#catching-the-casino class=hash-link aria-label="Direct link to Catching the Casino" title="Direct link to Catching the Casino"></a></h2>
|
||
<p>Let's go through a couple of scenarios and see if we can catch the casino cheating with some loaded dice. <strong>In every scenario we start with an assumption of fair dice</strong>, and then try our hand to figure out what the <em>actual</em> distribution was.</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=attempt-1>Attempt 1<a href=#attempt-1 class=hash-link aria-label="Direct link to Attempt 1" title="Direct link to Attempt 1"></a></h3>
|
||
<p>The casino is using two dice that are both biased low. How well can we recover the distribution?</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token keyword" style="color:hsl(301, 63%, 40%)">import</span><span class="token plain"> time</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"></span><span class="token keyword" style="color:hsl(301, 63%, 40%)">def</span><span class="token plain"> </span><span class="token function" style="color:hsl(221, 87%, 60%)">simulate_casino</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_dist</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d2_dist</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> n</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">10000</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">:</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> d1_vals </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> unfair_die</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_dist</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> n</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> d2_vals </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> unfair_die</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d2_dist</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> n</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> start </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> time</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">perf_counter</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> max_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> max_d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> final_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> final_d2 </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> optimize</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_vals </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+</span><span class="token plain"> d2_vals</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> end </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> time</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">perf_counter</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token keyword" style="color:hsl(301, 63%, 40%)">print</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token string" style="color:hsl(119, 34%, 47%)">"Simulated Annealing time: {:.02f}s"</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token builtin" style="color:hsl(119, 34%, 47%)">format</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">end </span><span class="token operator" style="color:hsl(221, 87%, 60%)">-</span><span class="token plain"> start</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> coef_range </span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">arange</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">13</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"> </span><span class="token operator" style="color:hsl(221, 87%, 60%)">-</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">.5</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">subplot</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">221</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">bar</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">coef_range</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> density_coef</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_dist</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> d2_dist</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> width</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">title</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token string" style="color:hsl(119, 34%, 47%)">'True Distribution'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">subplot</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">222</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">hist</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">d1_vals </span><span class="token operator" style="color:hsl(221, 87%, 60%)">+</span><span class="token plain"> d2_vals</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> bins</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">11</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">title</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token string" style="color:hsl(119, 34%, 47%)">'Empirical Distribution'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">subplot</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">223</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">bar</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">coef_range</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> density_coef</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">max_d1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> max_d2</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> width</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">title</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token string" style="color:hsl(119, 34%, 47%)">'Recovered Distribution'</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> plt</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">gcf</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">set_size_inches</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">10</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">10</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain" style=display:inline-block></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">simulate_casino</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 1000; Current score (higher is better): -22147.004400281654</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Simulated Annealing time: 0.30s</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p><img decoding=async loading=lazy alt=png src=/assets/images/_notebook_14_1-22c2867e2cee02c45b87635ab4d3b76a.png width=605 height=601 class=img_ev3q></p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=attempt-2>Attempt 2<a href=#attempt-2 class=hash-link aria-label="Direct link to Attempt 2" title="Direct link to Attempt 2"></a></h3>
|
||
<p>The casino now uses dice that are both biased towards 1 and 6.</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">simulate_casino</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Simulated Annealing time: 0.08s</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p><img decoding=async loading=lazy alt=png src=/assets/images/_notebook_16_1-eaa9ebc93d4557216c77a63df7df5192.png width=605 height=601 class=img_ev3q></p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=attempt-3>Attempt 3<a href=#attempt-3 class=hash-link aria-label="Direct link to Attempt 3" title="Direct link to Attempt 3"></a></h3>
|
||
<p>The casino will now use one die biased towards 1 and 6, and one die towards 3 and 4.</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">simulate_casino</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">3</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">12</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Simulated Annealing time: 0.09s</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p><img decoding=async loading=lazy alt=png src=/assets/images/_notebook_18_1-f61745c7c099b114becca8acb3175541.png width=605 height=601 class=img_ev3q></p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=attempt-4>Attempt 4<a href=#attempt-4 class=hash-link aria-label="Direct link to Attempt 4" title="Direct link to Attempt 4"></a></h3>
|
||
<p>We'll now finally go to a fair casino to make sure that we can still recognize a positive result.</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">simulate_casino</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token plain">np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">repeat</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> np</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">.</span><span class="token plain">repeat</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">6</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Simulated Annealing time: 0.02s</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p><img decoding=async loading=lazy alt=png src=/assets/images/_notebook_20_1-ea40789d2365d20a0725aca866680217.png width=605 height=601 class=img_ev3q></p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=attempt-5>Attempt 5<a href=#attempt-5 class=hash-link aria-label="Direct link to Attempt 5" title="Direct link to Attempt 5"></a></h3>
|
||
<p>We've so far been working with a large amount of data - 10,000 data points. Can we now scale things back to only 250 throws? We'll start with two dice biased high.</p>
|
||
<div class="language-python codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-python codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain">simulate_casino</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">(</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> </span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">[</span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">1</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"> </span><span class="token number" style="color:hsl(35, 99%, 36%)">2</span><span class="token operator" style="color:hsl(221, 87%, 60%)">/</span><span class="token number" style="color:hsl(35, 99%, 36%)">9</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">]</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">,</span><span class="token plain"></span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> n</span><span class="token operator" style="color:hsl(221, 87%, 60%)">=</span><span class="token number" style="color:hsl(35, 99%, 36%)">250</span><span class="token punctuation" style="color:hsl(119, 34%, 47%)">)</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<div class="codeBlockContainer_Ckt0 theme-code-block" style="--prism-background-color:hsl(230, 1%, 98%);--prism-color:hsl(230, 8%, 24%)"><div class=codeBlockContent_biex><pre tabindex=0 class="prism-code language-text codeBlock_bY9V thin-scrollbar" style="background-color:hsl(230, 1%, 98%);color:hsl(230, 8%, 24%)"><code class=codeBlockLines_e6Vv><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 1000; Current score (higher is better): -551.6995384525453</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 2000; Current score (higher is better): -547.7803673440676</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 3000; Current score (higher is better): -547.9805613193807</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 4000; Current score (higher is better): -546.7574874775273</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 5000; Current score (higher is better): -549.5798007672656</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 6000; Current score (higher is better): -545.0354060154496</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 7000; Current score (higher is better): -550.1134504086606</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 8000; Current score (higher is better): -549.9306537114975</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 9000; Current score (higher is better): -550.7075182119111</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Iteration: 10000; Current score (higher is better): -549.400679551826</span><br></span><span class=token-line style="color:hsl(230, 8%, 24%)"><span class="token plain"> Simulated Annealing time: 1.94s</span><br></span></code></pre><div class=buttonGroup__atx><button type=button aria-label="Copy code to clipboard" title=Copy class=clean-btn><span class=copyButtonIcons_eSgA aria-hidden=true><svg viewBox="0 0 24 24" class=copyButtonIcon_y97N><path fill=currentColor d="M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z"/></svg><svg viewBox="0 0 24 24" class=copyButtonSuccessIcon_LjdS><path fill=currentColor d=M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z /></svg></span></button></div></div></div>
|
||
<p><img decoding=async loading=lazy alt=png src=/assets/images/_notebook_22_1-210909ddb46467b78aa3f65c8ae519fd.png width=605 height=601 class=img_ev3q></p>
|
||
<p>The results are surprisingly good. While the actual optimization process took much longer to finish than in the other examples, we still have a very good guess. As a caveat though: the recovered distribution tends to overfit the data. That is, if the data doesn't fit the underlying distribution well, the model will also fail.</p>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id=conclusion>Conclusion<a href=#conclusion class=hash-link aria-label="Direct link to Conclusion" title="Direct link to Conclusion"></a></h2>
|
||
<p>Given the results above, we can see that we have indeed come up with a very good algorithm to determine the distribution of two dice given their results. As a benefit, we have even seen that results come back very quickly; it's not uncommon for the optimization to converge within a tenth of a second.</p>
|
||
<p>Additionally, we have seen that the algorithm can intuit the distribution even when there is not much data. While the final example shows that we can 'overfit' on the dataset, we can still get valuable information from a relatively small dataset.</p>
|
||
<p>We can declare at long last: <strong>the mathematicians have again triumphed over the casino</strong>.</p>
|
||
<hr>
|
||
<h2 class="anchor anchorWithStickyNavbar_LWe7" id=justification-of-simulated-annealing>Justification of Simulated Annealing<a href=#justification-of-simulated-annealing class=hash-link aria-label="Direct link to Justification of Simulated Annealing" title="Direct link to Justification of Simulated Annealing"></a></h2>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=why-simulated-annealing>Why Simulated Annealing?<a href=#why-simulated-annealing class=hash-link aria-label="Direct link to Why Simulated Annealing?" title="Direct link to Why Simulated Annealing?"></a></h3>
|
||
<p>So why even use an algorithm with a fancy title like Simulated Annealing? First of all, because the title is sexy. Second of all, because this is a reasonably complicated problem to try and solve. We have a parameter space where each value <span class=katex><span class=katex-mathml><math><semantics><mrow><msub><mi>p</mi><mrow><mi>i</mi><mi>j</mi></mrow></msub><mo>∈</mo><mo stretchy=false>(</mo><mn>0</mn><mo separator=true>,</mo><mn>1</mn><mo stretchy=false>)</mo><mo separator=true>;</mo><mi>i</mi><mo separator=true>,</mo><mi>j</mi><mo>∈</mo><mo stretchy=false>{</mo><mn>1</mn><mo separator=true>,</mo><mo>…</mo><mo separator=true>,</mo><mn>6</mn><mo stretchy=false>}</mo></mrow><annotation encoding=application/x-tex>p_{ij} \in (0, 1); i, j \in \{1, \ldots, 6\}</annotation></semantics></math></span><span class=katex-html aria-hidden=true><span class=base><span class=strut style=height:0.8252em;vertical-align:-0.2861em></span><span class=mord><span class="mord mathnormal">p</span><span class=msupsub><span class="vlist-t vlist-t2"><span class=vlist-r><span class=vlist style=height:0.3117em><span style=top:-2.55em;margin-left:0em;margin-right:0.05em><span class=pstrut style=height:2.7em></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight" style=margin-right:0.05724em>ij</span></span></span></span></span><span class=vlist-s></span></span><span class=vlist-r><span class=vlist style=height:0.2861em><span></span></span></span></span></span></span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>∈</span><span class=mspace style=margin-right:0.2778em></span></span><span class=base><span class=strut style=height:1em;vertical-align:-0.25em></span><span class=mopen>(</span><span class=mord>0</span><span class=mpunct>,</span><span class=mspace style=margin-right:0.1667em></span><span class=mord>1</span><span class=mclose>)</span><span class=mpunct>;</span><span class=mspace style=margin-right:0.1667em></span><span class="mord mathnormal">i</span><span class=mpunct>,</span><span class=mspace style=margin-right:0.1667em></span><span class="mord mathnormal" style=margin-right:0.05724em>j</span><span class=mspace style=margin-right:0.2778em></span><span class=mrel>∈</span><span class=mspace style=margin-right:0.2778em></span></span><span class=base><span class=strut style=height:1em;vertical-align:-0.25em></span><span class=mopen>{</span><span class=mord>1</span><span class=mpunct>,</span><span class=mspace style=margin-right:0.1667em></span><span class=minner>…</span><span class=mspace style=margin-right:0.1667em></span><span class=mpunct>,</span><span class=mspace style=margin-right:0.1667em></span><span class=mord>6</span><span class=mclose>}</span></span></span></span>, for a total of 12 different variables we are trying to optimize over. Additionally, given a 12-dimensional function we are trying to optimize, simulated annealing makes sure that we don't fall into a local minimum.</p>
|
||
<h3 class="anchor anchorWithStickyNavbar_LWe7" id=why-not-something-else>Why not something else?<a href=#why-not-something-else class=hash-link aria-label="Direct link to Why not something else?" title="Direct link to Why not something else?"></a></h3>
|
||
<p>This is a fair question. There are two classes of algorithms that can also be used to solve this problem: <a href=https://en.wikipedia.org/wiki/Nonlinear_programming target=_blank rel="noopener noreferrer">Non-linear optimization</a> methods, and the <a href=https://en.wikipedia.org/wiki/Expectation%E2%80%93maximization_algorithm target=_blank rel="noopener noreferrer">EM algorithm</a>.</p>
|
||
<ol>
|
||
<li>
|
||
<p>I chose not to use non-linear optimization simply because I'm a bit concerned that it will trap me in a local maximum. Instead of running multiple different optimizations from different starting points, I can just use simulated annealing to take that into account. In addition, throughout the course of testing the simulated annealing code converged <em>incredibly</em> quickly - far more quickly than any non-linear solver would be able to accomplish.</p>
|
||
</li>
|
||
<li>
|
||
<p>The EM Algorithm was originally what I intended to write this blog post with. Indeed, the post was inspired by the <a href=http://web.stanford.edu/class/stats366/hmmR2.html target=_blank rel="noopener noreferrer">crooked casino</a> example which uses the EM algorithm to solve it. However, after modeling the likelihood function I realized that the algebra would very quickly get out of hand. Trying to compute all the polynomial terms would not be fun, which would be needed to actually optimize for each parameter. So while the EM algorithm would likely be much faster in raw speed terms, the amount of time needed to program and verify it meant that I was far better off using a different method for optimization.</p>
|
||
</li>
|
||
</ol></div></article><nav class="pagination-nav docusaurus-mt-lg" aria-label="Blog post page navigation"><a class="pagination-nav__link pagination-nav__link--prev" href=/2016/04/tick-tock><div class=pagination-nav__sublabel>Older post</div><div class=pagination-nav__label>Tick tock...</div></a><a class="pagination-nav__link pagination-nav__link--next" href=/2016/06/event-studies-and-earnings-releases><div class=pagination-nav__sublabel>Newer post</div><div class=pagination-nav__label>Event studies and earnings releases</div></a></nav></main><div class="col col--2"><div class="tableOfContents_bqdL thin-scrollbar"><ul class="table-of-contents table-of-contents__left-border"><li><a href=#proving-we-can-detect-cheating class="table-of-contents__link toc-highlight">Proving we can detect cheating</a><li><a href=#the-edge-cases class="table-of-contents__link toc-highlight">The Edge Cases</a><ul><li><a href=#edge-case-1 class="table-of-contents__link toc-highlight">Edge Case 1</a><li><a href=#edge-case-2 class="table-of-contents__link toc-highlight">Edge Case 2</a></ul><li><a href=#detection-conclusion class="table-of-contents__link toc-highlight">Detection Conclusion</a><li><a href=#simulated-annealing class="table-of-contents__link toc-highlight">Simulated Annealing</a><ul><li><a href=#deriving-the-likelihood-function class="table-of-contents__link toc-highlight">Deriving the Likelihood function</a><li><a href=#the-process-of-simulated-annealing class="table-of-contents__link toc-highlight">The process of Simulated Annealing</a></ul><li><a href=#the-actual-code class="table-of-contents__link toc-highlight">The actual code</a><li><a href=#catching-the-casino class="table-of-contents__link toc-highlight">Catching the Casino</a><ul><li><a href=#attempt-1 class="table-of-contents__link toc-highlight">Attempt 1</a><li><a href=#attempt-2 class="table-of-contents__link toc-highlight">Attempt 2</a><li><a href=#attempt-3 class="table-of-contents__link toc-highlight">Attempt 3</a><li><a href=#attempt-4 class="table-of-contents__link toc-highlight">Attempt 4</a><li><a href=#attempt-5 class="table-of-contents__link toc-highlight">Attempt 5</a></ul><li><a href=#conclusion class="table-of-contents__link toc-highlight">Conclusion</a><li><a href=#justification-of-simulated-annealing class="table-of-contents__link toc-highlight">Justification of Simulated Annealing</a><ul><li><a href=#why-simulated-annealing class="table-of-contents__link toc-highlight">Why Simulated Annealing?</a><li><a href=#why-not-something-else class="table-of-contents__link toc-highlight">Why not something else?</a></ul></ul></div></div></div></div></div><footer class=footer><div class="container container-fluid"><div class="footer__bottom text--center"><div class=footer__copyright>Copyright © 2024 Bradlee Speice</div></div></div></footer></div> |