<?xml version="1.0" encoding="UTF-8"?>
<rss  xmlns:atom="http://www.w3.org/2005/Atom" 
      xmlns:media="http://search.yahoo.com/mrss/" 
      xmlns:content="http://purl.org/rss/1.0/modules/content/" 
      xmlns:dc="http://purl.org/dc/elements/1.1/" 
      version="2.0">
<channel>
<title>0^0</title>
<link>https://your-website-url.example.com/index.html</link>
<atom:link href="https://your-website-url.example.com/index.xml" rel="self" type="application/rss+xml"/>
<description>A blog built with Quarto</description>
<generator>quarto-1.3.450</generator>
<lastBuildDate>Sun, 15 Mar 2026 16:00:00 GMT</lastBuildDate>
<item>
  <title>我們知道 Agentic AI 很厲害，但他們找答案的方法真的有效率嗎 - MADQA benchmark</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/huggingface/001.html</link>
  <description><![CDATA[ 



<p>這篇 paper 給了一套 2250 題題庫，定義了衡量多模態 AI agent 「搜尋效率」的方法，並給出了有趣的觀察。</p>
<p>先講結論，Agent在搜尋上很擅長，但效率不如人類，可能是因為推理能力不足，agent甚至用暴力搜尋的方法 彌補了他推理能力不強的短版。</p>
<p><img src="https://your-website-url.example.com/posts/huggingface/images/001-Human-win.png" class="img-fluid"></p>
<p>一般來說，代理人 (AI agent) 在訓練時，有個 Reward Function，我們用人為定義獎勵機制，讓 agent 往我們想要的方向發展。 但我們今天不是要講這個，我們是要比較 agent 訓練出來的成果，跟人類專家比起來，是贏是輸? 而比較標準是什麼? 比速度的話 agent 當然會贏，所以說要定義出類似「精準度」的東西。</p>
<p>這個東西叫做 Multimodal Agentic document QA benchmark。顧名思義，他要測試多模態(文字+圖片)的代理人，讀取多份文件後，問答表現的能力。</p>
<ul>
<li>MADQA資料集: 2250個人工撰寫的Q&amp;A。</li>
<li>提供之參考文件: 來源自 800 份多樣化的文件，從金融報告到法律文件，從單頁到800多頁。視覺差異性大。文件之間在版面視覺密度差異巨大，金融和政府的文件表格密度高，技術文件圖形多等等。</li>
<li>難度:
<ul>
<li>多跳 (multi-hop) 問題。任務無法透過單一步驟的檢索解決。需進行規畫、導航，整合來自多個不連續甚至多個文件的資訊 (8.3%跨頁，9.0%跨文件)。最終聚合成答案。</li>
<li>單純關鍵字匹配 (n-gram) 無法解決。</li>
<li>視覺感知: 多達 58% 問題受益於理解結構化版面、表格或視覺元素。</li>
</ul></li>
<li>邊界:
<ul>
<li>封閉世界: 答案完全從提供的資料庫中導出，要有依據。在無文件情況下，猜對機率僅11%。(其中3%來自運氣，8%可能來自訓練汙染)</li>
<li>歸因: 答案必須準確歸因於最小的證據集。懲罰冗餘。</li>
</ul></li>
</ul>
<p>如何衡量，agent的表現? 除了答對問題?</p>
<p>本文引用了 Kuiper Statistic (庫柏統計量), K value。</p>
<blockquote class="blockquote">
<p>〔先講一個錯誤版本〕 假設題目的難度標記從 1 分到 100分，那我們花的時間，預計也要跟它呈正比。例如在難度1分的題目上若花 1分鐘，在難度100分的題目就是花 100分鐘。(假設這個難度量表有設計好)。那Kuiper Statistic其實很好理解，就是「多花的最長時間」加上「少花的最長時間」。比方說 agent 表現最差(最浪費時間) 是在難度3分的題目上花了10分鐘(超出預期7分鐘)，然後太快放棄的是在難度70分的問題只花了 55分鐘(少花了15分鐘)，那這個agent 的K value就是 7 + 15 = 22。</p>
</blockquote>
<p>直觀上我們想這樣定義，但是，量表怎麼設計? 誰設計的準? 沒有辦法。而且，客觀上我們只知道 agent 答對與否(0分或1分)。沒有對於答案品質的量化指標。</p>
<p>所以我們改一種方式。因為我們題目很多，所以可以用機率模型來思考，也就是研究「答對率」與「花費時間」的關係。我們期望他是一個常數。</p>
<blockquote class="blockquote">
<p>假設有2000道題，我們把所有題目根據「agent花費的時間」(或者說，搜尋使用的step數，總之就是一個正實數)，由小排到大。 在這個排序下，我們希望，不管花多少時間，agent的答對率是「均勻的」。直覺來說，如果花比較少時間的題目 答對率較高，花較多時間的題目，答對率較低，那不就代表，其實那些花較多時間的題目是多餘的，應該要降低才對。那才是均勻分配時間的方法。</p>
</blockquote>
<p>但具體來說，可能花費時間 = 20 的只有一個取樣點，這要怎麼算答對率? 這時就是利用 paper 中的計算 cumulative 的方法來解決。在這邊就先不仔細展開。</p>
<p><img src="https://your-website-url.example.com/posts/huggingface/images/001-Kuiper.png" class="img-fluid"></p>
<p>研究結果: 有趣的發現是，</p>
<ul>
<li>Agent &gt; RAG</li>
<li>Agent != Human。代理人與人類擅長的問題很不一樣。agent常依賴「暴力搜尋」彌補策略不足。</li>
<li>Agent ~ Oracle * 80%。 代理人擅長檢索，但不擅長推理。</li>
<li>Agent’s K value &gt;&gt; Human’s K value。代理人常花多餘的時間在搜索。</li>
<li>隨著模型能力提升，檢索失敗類型的Error逐漸減少，轉向 理解失敗。證明了檢索是已被解決的問題。</li>
<li>靈活的搜尋策略(用不同詞彙或方式重新搜尋) 與成功率成呈正相關。</li>
<li>!? 跨文件比單文件容易? 原因不明。</li>
</ul>
<hr>
<section id="結語" class="level2">
<h2 class="anchored" data-anchor-id="結語">結語</h2>
<p>學者們設計了一套 open book 題庫，目的不是在難倒AI，最強模型答對率已經有七成，但重點是，這些agent到底怎麼找出答案的，我們在剖析他們的搜尋方法 (不能說解剖思考過程，那是另一回事了)。</p>
</section>
<section id="實驗結果展示" class="level2">
<h2 class="anchored" data-anchor-id="實驗結果展示">實驗結果展示</h2>
<p><img src="https://your-website-url.example.com/posts/huggingface/images/001-table3.png" class="img-fluid"></p>


</section>

 ]]></description>
  <category>HuggingFace Papers</category>
  <guid>https://your-website-url.example.com/posts/huggingface/001.html</guid>
  <pubDate>Sun, 15 Mar 2026 16:00:00 GMT</pubDate>
</item>
<item>
  <title>Optimal Stopping - The Secretary Problem</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/optimal-stopping/secretary-problem.html</link>
  <description><![CDATA[ 



<p>柏拉圖有一個很有名的故事：他要弟子去麥田裡，不准回頭地摘下一株最大的麥穗。</p>
<p>結果弟子為了等後面「可能」更大的，最後什麼都沒摘到。</p>
<p>這個故事大家可能都聽過，但如果我們把它變成一個嚴格的數學問題呢？</p>
<section id="問題設定" class="level3">
<h3 class="anchored" data-anchor-id="問題設定">1. 問題設定</h3>
<p>假設你現在是老闆，要面試 <img src="https://latex.codecogs.com/png.latex?N"> 個秘書，面試完必須立刻決定要不要錄取，不能吃回頭草。</p>
<ul>
<li>你遇到第一個人，他是目前最好的機率是百分之百，也就是 1。</li>
<li>遇到第二個人，他比第一個好的機率是 <img src="https://latex.codecogs.com/png.latex?1/2">。</li>
<li>第三個人，剛好是目前這三人裡最優秀的機率，是 <img src="https://latex.codecogs.com/png.latex?1/3">。</li>
<li>以此類推，第 <img src="https://latex.codecogs.com/png.latex?k"> 個人成為「目前為止最好」的機率，剛好就是 <img src="https://latex.codecogs.com/png.latex?1/k">。這每一個都是獨立事件。</li>
</ul>
<p>問題來了：你要怎麼選，才能讓自己選到那個「絕對第一名」的機率最大？</p>
</section>
<section id="逆向歸納法-backward-induction" class="level2">
<h2 class="anchored" data-anchor-id="逆向歸納法-backward-induction">2. 逆向歸納法 (Backward Induction)</h2>
<p>遇到這種不知從何下手的問題，最暴力的解法，就是從結果往回推。</p>
<p>秘書問題的本質，其實是最簡單的一種動態規劃。 如果你有學過任何 Dynamic Programming 的話，現實中的 DP 絕對比這個還要複雜非常多。 這裡 optimal stopping 是一個特別簡單的情形，數學上叫做 Backward Induction，逆向歸納法。</p>
<p>如果你沒學過也完全沒關係，因為我們現在馬上來看一下，它到底在幹嘛。</p>
<p>想像一下，你站在面試的最後一關。如果前面都沒選，最後一個就算再爛，你也只能硬著頭皮選下去。因為你已經知道最後一步的下場，所以我們可以開始「往回倒推」。</p>
<section id="確立解的形狀黃金交叉" class="level3">
<h3 class="anchored" data-anchor-id="確立解的形狀黃金交叉">3. 確立解的形狀：黃金交叉</h3>
<p>在往回推的過程中，我們每一步其實都只在做一件事：拿「天平」秤兩邊的重量。 左邊是「我現在就停下來」的期望值；右邊是「我繼續面試下去」的期望值。哪邊重，我們就選哪邊。 - 如果你太早停下來，樣本數根本不夠，所以「停下來」的期望值一開始是很差的。 - 但反過來說，如果你一直撐著不選，隨著剩下的人越來越少，「繼續找」的期望值也會無情地往下跌。</p>
<p>既然一邊在漲、一邊在跌，這兩條線，注定會產生一個「黃金交叉」。</p>
<p>這個交叉點非常重要，它幫我們確立了「解的形狀」： - 在交叉點之前，繼續找的期望值比較高，所以不管遇到誰，我們一律放棄； - 但是，一旦越過了這個門檻，只要遇到「目前為止最好的人」，我們就毫不猶豫地錄取他！</p>
</section>
<section id="bruss-algorithm-與-odds-的推導" class="level3">
<h3 class="anchored" data-anchor-id="bruss-algorithm-與-odds-的推導">4. Bruss Algorithm 與 Odds 的推導</h3>
<p>既然知道了策略是切出一個門檻，那這個門檻具體到底在幾趴？這時候，我們就要請出 Optimal Stopping 領域最漂亮的公式：Bruss Algorithm。</p>
<p>我們畫一個狀態圖來推導。</p>
<p>假設每一個面試者是最好人選的機率是 <img src="https://latex.codecogs.com/png.latex?P">，不是最好的機率是 <img src="https://latex.codecogs.com/png.latex?Q">。如果選到了不是最好的人，比賽就要繼續，這就是走 <img src="https://latex.codecogs.com/png.latex?Q"> 的路線；如果抽中最好的人，就是走 <img src="https://latex.codecogs.com/png.latex?P"> 的路線。 假設我們在第 <img src="https://latex.codecogs.com/png.latex?S"> 個人的時候決定停下來，我們把天平的兩端拿出來比：</p>
<ul>
<li><p>天平的一邊，是你選擇「現在就停」。那你後面必須全部槓龜，才會證明你現在選的是對的。 所以機率是從第 <img src="https://latex.codecogs.com/png.latex?S+1"> 個 <img src="https://latex.codecogs.com/png.latex?Q">，一路連乘到第 <img src="https://latex.codecogs.com/png.latex?N"> 個 <img src="https://latex.codecogs.com/png.latex?Q">。(語音讀法：從 Q s 加 1，一路連乘到 Q n)</p></li>
<li><p>天平的另一邊，是你選擇「繼續找」。要贏的話，代表後面「至少要發生一次」選到最好的人。也就是把剛才那一長串的 <img src="https://latex.codecogs.com/png.latex?Q"> 連乘裡面，把其中一個 <img src="https://latex.codecogs.com/png.latex?Q"> 換成 <img src="https://latex.codecogs.com/png.latex?P"> 的所有組合，全部加總起來。</p></li>
</ul>
<p>當我們把天平兩端相等，也就是找出那個黃金交叉點的時候，神奇的事情發生了。 只要把右邊的一大串加總，除以左邊的 <img src="https://latex.codecogs.com/png.latex?Q"> 連乘。每一個組合裡的 <img src="https://latex.codecogs.com/png.latex?Q"> 都會被消掉，只剩下 <img src="https://latex.codecogs.com/png.latex?P"> 除以 <img src="https://latex.codecogs.com/png.latex?Q">。</p>
<p><img src="https://latex.codecogs.com/png.latex?P"> 除以 <img src="https://latex.codecogs.com/png.latex?Q"> 是什麼？在機率論裡，這就叫做 Odds，賠率！ Bruss 演算法證明了，只要你從最後面開始，把每一個人的 Odds 加起來。當這個總和「剛好超過 1」的那一瞬間，就是你該設立門檻的完美停損點！</p>
</section>
<section id="結論" class="level3">
<h3 class="anchored" data-anchor-id="結論">5. 結論</h3>
<p>這個數學公式非常漂亮，算出秘書問題的答案大約是 37%。很多人看完這種影片，就會傻傻地把 37% 當作人生真理去套用。 但說實話，這在現實生活中是不完全合用的。</p>
<p>為什麼？因為數學公式把「選到絕對的第一名」當作 100 分，選到第二名、第三名，甚至是倒數第一名，全部當作 0 分。</p>
<p>但在現實面試、甚至找伴侶的時候，如果你已經看過了 80% 的人，此時遇到一個綜合評估是「目前第二好」的人選，你真的要為了那虛無縹緲的「絕對第一」，而把眼前的第二名放棄掉嗎？當然不該！</p>
<p>現實世界不是非黑即白的 0 與 1。當我們把第二名、第三名的價值也考慮進去時，這個遊戲的規則就會改變。解的形狀不再是單一一個門檻，而是會出現多重門檻（Multiple Thresholds）—— 隨著時間流逝，你會願意妥協的標準會像階梯一樣慢慢放寬。</p>
<p>至於這個「多重門檻」在數學上又該怎麼計算？這其實是 Optimal Stopping 裡更進階的變體。如果大家對這種「更貼近真實人性」的數學推導有興趣，我們下一支影片再來好好聊聊。</p>


</section>
</section>

 ]]></description>
  <category>Optimal Stopping</category>
  <guid>https://your-website-url.example.com/posts/optimal-stopping/secretary-problem.html</guid>
  <pubDate>Wed, 25 Feb 2026 16:00:00 GMT</pubDate>
</item>
<item>
  <title>The $2,000 Math Problem I Solved (But Got Paid $0)</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/scripts/steaks.html</link>
  <description><![CDATA[ 



<section id="part-1-the-story" class="level2">
<h2 class="anchored" data-anchor-id="part-1-the-story">Part 1: The Story</h2>
<p>老話說得好：『主動找上門的生意，通常不是好生意。』我以為我已經學乖了，但這次… 我還是沒學乖。</p>
<p>幾週前，矽谷著名的 AI 公司 Mercor 主動發信給我，邀請我為他們的 AI 模型出數學題。 合約看起來很誘人：時薪 50 ~ 90 美金。如果通過審核，還有額外的 Signing Bonus。</p>
<p>當時我已經一陣子沒收入了，心想：這不就是為我準備的嗎？ 我想起了以前看過的一個幾何移動問題，但我不會證明。 我花了整整兩天，進入了完全的心流狀態，想破了頭，終於證明出來了。</p>
<p>後來我去查資料，才發現這其實是 2018 年 IMO Shortlist 的 C3 難題。 說實話，還好我當時沒去查。如果知道是 IMO C3，而且他只要求證明一個比較弱的結論，我應該早就放棄了。 正因為不知道，我誤打誤撞，給出了一個比 IMO 解答更強的結果。我蠻相信這是一個新的發現。</p>
<p>我當時覺得：這是我今年最得意的作品，這 2000 美金拿定了。</p>
<p>結果呢？ 提交三天，審核中。 提交五天… 合約整個被單方面解除。不要說 2000 美金，我連其他好幾題還在審核中的費用都沒拿到。理由？沒有理由。沒有審核通過，當然，也就沒有錢。</p>
<p>根據合約，既然他們沒付錢，這題的 Intellectual Property (IP) 就還屬於我。 所以我想，與其讓這道漂亮的證明躺在我的硬碟裡發霉，不如把它免費獻給 YouTube 的觀眾。</p>
<p>沒錯，今天我要教你們這道『價值 2000 美金』的題目。 他們沒眼光買單，那是他們的損失。 現在，我們來看看這題數學，到底有多美。」</p>
</section>
<section id="part-2-the-meat數學部分" class="level2">
<h2 class="anchored" data-anchor-id="part-2-the-meat數學部分">Part 2: The Meat（數學部分）</h2>
<section id="遊戲設定牛排塔-the-steak-tower" class="level3">
<h3 class="anchored" data-anchor-id="遊戲設定牛排塔-the-steak-tower">1. 遊戲設定：牛排塔 (The Steak Tower)</h3>
<p>讓我們深入問題的核心。想像一張桌子上有 1,025 個盤子。在最左邊的盤子（第 0 號盤子）上，我們有一座疊了 1,024 塊牛排的塔。目標很簡單：把所有的牛排都移動到最右邊的最後一個盤子上。但我們有一個非常特殊的物理限制。</p>
<p>你只能移動一疊牛排中最上面那一塊。而且它可以移動的距離，取決於它離開時那一疊牛排的目前高度。如果一個盤子上有 <img src="https://latex.codecogs.com/png.latex?k"> 塊牛排，最上面那一塊就可以跳到距離 <img src="https://latex.codecogs.com/png.latex?k"> 以內的任何盤子上。簡而言之：塔越高，射程越遠。</p>
<p>讓我們先從簡單的開始。1 塊牛排，距離 1？很簡單。高度是 1，跳躍距離 1。需要 1 步。</p>
<p>如果是 2 塊牛排，距離 2 呢？你不能直接跳底下的牛排，因為它被壓住了。如果你把最上面的牛排（牛排 A）直接跳到第 2 號盤子，牛排 B 就會孤零零地留在第 0 號盤子上。現在高度變成了 1，所以牛排 B 只能跳到第 1 號盤子。你需要額外一步才能把它移動到第 2 號盤子，總共需要 3 步。這就是這個遊戲最基本的摩擦力。</p>
</section>
<section id="關於-imo石頭與牛排的關聯-the-imo-connection" class="level3">
<h3 class="anchored" data-anchor-id="關於-imo石頭與牛排的關聯-the-imo-connection">2. 關於 IMO：石頭與牛排的關聯 (The IMO Connection)</h3>
<p>數學愛好者可能會認出這個問題。這是 2018 年國際數學奧林匹亞（IMO）短名單問題 C3 的變形，只不過原題移動的是石頭。但當我在為 Mercor 設計這道題目時，我把它們換成了牛排——部分原因是牛排疊起來比較合理，另一部分原因是我想要提高難度。</p>
<p>在 IMO 的版本中，你只需要證明一個較寬鬆的下界：<img src="https://latex.codecogs.com/png.latex?%5Csum_%7Bi=1%7D%5E%7Bn%7D%20%5Clceil%20n/i%20%5Crceil">。那個證明很優雅——你幫牛排編號，然後證明第 1 塊牛排總是需要 <img src="https://latex.codecogs.com/png.latex?n"> 步，第 2 塊牛排至少需要 <img src="https://latex.codecogs.com/png.latex?n/2"> 步，依此類推。但那只是一個估算，它並沒有告訴你如何達成。事實上，這個下界只有在 <img src="https://latex.codecogs.com/png.latex?n%20=%201,%202,%203,%204,%205,%207"> 時才是緊緻的（tight）。對於其他的數字，真正的答案要高得多。我們需要一個更精確的工具。</p>
</section>
<section id="找出規律分而治之-divide-and-conquer" class="level3">
<h3 class="anchored" data-anchor-id="找出規律分而治之-divide-and-conquer">3. 找出規律：分而治之 (Divide and Conquer)</h3>
<p>讓我們嘗試另一種哲學：分而治之。假設 <img src="https://latex.codecogs.com/png.latex?F(n)"> 是將 <img src="https://latex.codecogs.com/png.latex?n"> 塊牛排移動跨越距離 <img src="https://latex.codecogs.com/png.latex?n"> 所需的最少步數。如果我們在第 <img src="https://latex.codecogs.com/png.latex?k"> 號盤子設立一個檢查點呢？</p>
<p>計畫是這樣的：我們直接發射 1 塊牛排到終點線（第 <img src="https://latex.codecogs.com/png.latex?n"> 號盤子），這利用了完整的高度。接著，我們將 <img src="https://latex.codecogs.com/png.latex?(n-k-1)"> 塊牛排直接飛到第 <img src="https://latex.codecogs.com/png.latex?k"> 號盤子。然後我們用 <img src="https://latex.codecogs.com/png.latex?F(k)"> 步把剩下的 <img src="https://latex.codecogs.com/png.latex?k"> 塊牛排移動到第 <img src="https://latex.codecogs.com/png.latex?k"> 號盤子。現在整個團隊（除了一塊牛排）都在檢查點了。接下來，我們從第 <img src="https://latex.codecogs.com/png.latex?k"> 號盤子塔頂飛 <img src="https://latex.codecogs.com/png.latex?(k-1)"> 塊牛排到第 <img src="https://latex.codecogs.com/png.latex?n"> 號盤子。最後，我們用 <img src="https://latex.codecogs.com/png.latex?F(n-k)"> 步將剩下的 <img src="https://latex.codecogs.com/png.latex?(n-k)"> 塊牛排移動到終點。</p>
<p>總成本是多少？<img src="https://latex.codecogs.com/png.latex?(n-k-1)%20+%20F(k)%20+%201%20+%20(k-1)%20+%20F(n-k)">。它可以漂亮地化簡為： <img src="https://latex.codecogs.com/png.latex?F(n)%20=%20(n-1)%20+%20F(k)%20+%20F(n-k)"> 但這真的是最佳解嗎？這感覺很直觀，但在數學中，直覺是證明危險的替代品。如果有一塊牛排「跳過」了檢查點怎麼辦？如果有些牛排「提早出發」而沒有在第 <img src="https://latex.codecogs.com/png.latex?k"> 號盤子等待呢？如果這種遞迴結構被打破，這整個公式就會瓦解。</p>
</section>
<section id="突破點手術證明-the-surgery-proof" class="level3">
<h3 class="anchored" data-anchor-id="突破點手術證明-the-surgery-proof">4. 突破點：「手術」證明 (The “Surgery” Proof)</h3>
<p>這是我卡住最久的地方。我試圖找到一個遞減的變量（decreasing invariant），但都行不通。然後，我發現了「手術」——這是一種能嚴格證明這種遞迴結構絕不會比其他任何可能策略更糟的方法。</p>
<p>想像任何一種隨機、混亂的移動方式。我們找出一個最小的索引值 <img src="https://latex.codecogs.com/png.latex?k%5E*">，從這個位置有任何牛排直接跳到終點 <img src="https://latex.codecogs.com/png.latex?n">。如果我們有一些移動「越過」了這個 <img src="https://latex.codecogs.com/png.latex?k%5E*">——比方說，從 <img src="https://latex.codecogs.com/png.latex?i%20%5Cto%20j%20%5Cto%20p">，其中 <img src="https://latex.codecogs.com/png.latex?i%20%3C%20k%5E*%20%3C%20j">——我們就進行手術。</p>
<p>我們把 <img src="https://latex.codecogs.com/png.latex?%5C%7B(i,%20j),%20(j,%20p)%5C%7D"> 替換成 <img src="https://latex.codecogs.com/png.latex?%5C%7B(i,%20k%5E*),%20(k%5E*,%20p)%5C%7D">。我們可以證明這樣總是合法的。<img src="https://latex.codecogs.com/png.latex?i%20%5Cto%20k%5E*"> 是一個較短的跳躍，而 <img src="https://latex.codecogs.com/png.latex?k%5E*"> 保證有足夠的容量，因為它是前往終點的發射台。透過重複進行這種手術，我們消除了所有繞過我們檢查點的移動。我們有效地將任何「狂野」的策略簡化成一種有結構的遞迴策略，而且沒有增加任何一步。</p>
<p>這個簡化就是關鍵。它證明了最小成本必定滿足我們的遞迴公式。我們現在要做的，就只剩下解開它而已。</p>
</section>
</section>
<section id="part-3-the-ending" class="level2">
<h2 class="anchored" data-anchor-id="part-3-the-ending">Part 3: The ending</h2>
<p>雖然 Mercor 沒有付錢給我，但我還是很高興能把這個漂亮的數學題目分享給大家。希望你們喜歡這道題目的美麗證明，並且從中獲得啟發。</p>
<div class="quarto-video ratio ratio-16x9"><iframe data-external="1" src="https://www.youtube.com/embed/al7Vt7U19FU" title="" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe></div>


</section>

 ]]></description>
  <category>IMO</category>
  <guid>https://your-website-url.example.com/posts/scripts/steaks.html</guid>
  <pubDate>Sun, 25 Jan 2026 16:00:00 GMT</pubDate>
</item>
<item>
  <title>Poker Lesson 7 - 比大小遊戲 (完整版)</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/poker/lesson_7_comparison_full.html</link>
  <description><![CDATA[ 



<p>今天我們繼續比大小遊戲，但是上次假設，若先手 Player A check，則強制攤牌。這次我們來討論更一般的情況: Player B 可以選擇主動下注。</p>
<p>不過我們還是先忽略可以加注 (raise) 的情況。</p>
<section id="遊戲規則-01-連續版本" class="level3">
<h3 class="anchored" data-anchor-id="遊戲規則-01-連續版本">遊戲規則: [0,1] 連續版本</h3>
<ul>
<li><strong>玩家</strong>：Player A 與 Player B。</li>
<li><strong>底池 (Pot)</strong>：<img src="https://latex.codecogs.com/png.latex?P"> 元（可視為雙方起始強迫下注 <img src="https://latex.codecogs.com/png.latex?P/2">）。</li>
<li><strong>發牌</strong>：雙方從 <img src="https://latex.codecogs.com/png.latex?%5B0,1%5D"> 均勻分布抽取一個數字作為自己的牌面數字，彼此互不知情。</li>
<li><strong>攤牌時勝負判定</strong>：
<ul>
<li>數字較大者獲勝，贏走底池。</li>
<li>若數字相同則平手，雙方拿回各自的下注。</li>
</ul></li>
<li><strong>下注流程</strong>：
<ul>
<li>設定每次下注金額為 <img src="https://latex.codecogs.com/png.latex?B"> 元。</li>
<li>Player A（先手）：可以選擇 <strong>下注 (Bet)</strong> 或 <strong>過牌 (Check)</strong>。</li>
<li>若 Player A 選擇 <strong>過牌 (Check)</strong>，則輪到 Player B 行動，B 同樣可以選擇 <strong>下注</strong> 或 <strong>過牌</strong>。</li>
<li>若 Player A 選擇 <strong>下注 (Bet)</strong>，則輪到 Player B 行動，B 可以選擇 <strong>跟注 (Call)</strong> 或 <strong>棄牌 (Fold)</strong>。</li>
</ul></li>
</ul>
<div class="cell">
<div class="cell-output-display">
<div id="fig-full-game-tree" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<div>
<svg width="672" height="480" viewbox="0.00 0.00 733.49 327.80" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" style="; max-width: none; max-height: none">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 323.8)">
<title>
GT_Advanced
</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-323.8 729.49,-323.8 729.49,4 -4,4"></polygon> <!-- A1 --> <g id="node1" class="node">
<title>
A1
</title>
<ellipse fill="white" stroke="#15c043" stroke-width="2" cx="44.81" cy="-168" rx="44.63" ry="44.63"></ellipse> <text text-anchor="middle" x="44.81" y="-163.8" font-family="Helvetica, Arial, sans-serif" font-size="14.00">Player A</text> </g> <!-- B1 --> <g id="node2" class="node">
<title>
B1
</title>
<ellipse fill="white" stroke="#1565c0" stroke-width="2" cx="230.07" cy="-222" rx="44.04" ry="44.04"></ellipse> <text text-anchor="middle" x="230.07" y="-217.8" font-family="Helvetica, Arial, sans-serif" font-size="14.00">Player B</text> </g> <!-- A1&#45;&gt;B1 --> <g id="edge1" class="edge">
<title>
A1-&gt;B1
</title>
<path fill="none" stroke="black" d="M88.32,-180.52C114.99,-188.38 149.55,-198.57 177.75,-206.88"></path> <polygon fill="black" stroke="black" points="176.85,-210.26 187.43,-209.73 178.83,-203.55 176.85,-210.26"></polygon> <text text-anchor="middle" x="137.72" y="-205.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 下注 (Bet) </text> </g> <!-- B2 --> <g id="node3" class="node">
<title>
B2
</title>
<ellipse fill="white" stroke="#1565c0" stroke-width="2" cx="230.07" cy="-115" rx="44.04" ry="44.04"></ellipse> <text text-anchor="middle" x="230.07" y="-110.8" font-family="Helvetica, Arial, sans-serif" font-size="14.00">Player B</text> </g> <!-- A1&#45;&gt;B2 --> <g id="edge4" class="edge">
<title>
A1-&gt;B2
</title>
<path fill="none" stroke="black" d="M88.32,-155.71C114.99,-147.99 149.55,-138 177.75,-129.84"></path> <polygon fill="black" stroke="black" points="178.8,-133.18 187.43,-127.04 176.85,-126.46 178.8,-133.18"></polygon> <text text-anchor="middle" x="137.72" y="-152.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 過牌 (Check) </text> </g> <!-- Outcome_A_Bet_B_Call --> <g id="node5" class="node">
<title>
Outcome_A_Bet_B_Call
</title>
<path fill="#f5f5f5" stroke="black" d="M490.25,-319.6C490.25,-319.6 422.78,-319.6 422.78,-319.6 416.78,-319.6 410.78,-313.6 410.78,-307.6 410.78,-307.6 410.78,-276.4 410.78,-276.4 410.78,-270.4 416.78,-264.4 422.78,-264.4 422.78,-264.4 490.25,-264.4 490.25,-264.4 496.25,-264.4 502.25,-270.4 502.25,-276.4 502.25,-276.4 502.25,-307.6 502.25,-307.6 502.25,-313.6 496.25,-319.6 490.25,-319.6"></path> <text text-anchor="middle" x="456.52" y="-296.2" font-family="Helvetica, Arial, sans-serif" font-size="14.00">結局 1: 攤牌</text> <text text-anchor="middle" x="456.52" y="-279.4" font-family="Helvetica, Arial, sans-serif" font-size="14.00">(池底: P+2B)</text> </g> <!-- B1&#45;&gt;Outcome_A_Bet_B_Call --> <g id="edge2" class="edge">
<title>
B1-&gt;Outcome_A_Bet_B_Call
</title>
<path fill="none" stroke="black" d="M272.5,-234.92C308.58,-246.17 361.17,-262.57 400.72,-274.91"></path> <polygon fill="black" stroke="black" points="399.89,-278.32 410.48,-277.95 401.97,-271.63 399.89,-278.32"></polygon> <text text-anchor="middle" x="322.43" y="-262.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 跟注 (Call) </text> </g> <!-- Outcome_A_Bet_B_Fold --> <g id="node6" class="node">
<title>
Outcome_A_Bet_B_Fold
</title>
<path fill="#f5f5f5" stroke="black" d="M492.02,-245.6C492.02,-245.6 421.02,-245.6 421.02,-245.6 415.02,-245.6 409.02,-239.6 409.02,-233.6 409.02,-233.6 409.02,-202.4 409.02,-202.4 409.02,-196.4 415.02,-190.4 421.02,-190.4 421.02,-190.4 492.02,-190.4 492.02,-190.4 498.02,-190.4 504.02,-196.4 504.02,-202.4 504.02,-202.4 504.02,-233.6 504.02,-233.6 504.02,-239.6 498.02,-245.6 492.02,-245.6"></path> <text text-anchor="middle" x="456.52" y="-222.2" font-family="Helvetica, Arial, sans-serif" font-size="14.00">結局 2: A 獲勝</text> <text text-anchor="middle" x="456.52" y="-205.4" font-family="Helvetica, Arial, sans-serif" font-size="14.00">(B 棄牌)</text> </g> <!-- B1&#45;&gt;Outcome_A_Bet_B_Fold --> <g id="edge3" class="edge">
<title>
B1-&gt;Outcome_A_Bet_B_Fold
</title>
<path fill="none" stroke="black" d="M274.35,-221.23C309.78,-220.6 360.18,-219.7 398.83,-219.01"></path> <polygon fill="black" stroke="black" points="398.96,-222.51 408.89,-218.83 398.83,-215.51 398.96,-222.51"></polygon> <text text-anchor="middle" x="322.43" y="-223.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 棄牌 (Fold) </text> </g> <!-- A2 --> <g id="node4" class="node">
<title>
A2
</title>
<ellipse fill="white" stroke="#15c043" stroke-width="2" cx="456.52" cy="-125" rx="44.63" ry="44.63"></ellipse> <text text-anchor="middle" x="456.52" y="-120.8" font-family="Helvetica, Arial, sans-serif" font-size="14.00">Player A</text> </g> <!-- B2&#45;&gt;A2 --> <g id="edge6" class="edge">
<title>
B2-&gt;A2
</title>
<path fill="none" stroke="black" d="M274.35,-116.93C310.6,-118.54 362.52,-120.86 401.49,-122.59"></path> <polygon fill="black" stroke="black" points="401.46,-126.1 411.61,-123.04 401.77,-119.1 401.46,-126.1"></polygon> <text text-anchor="middle" x="322.43" y="-123.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 下注 (Bet) </text> </g> <!-- Outcome_Check_Check --> <g id="node7" class="node">
<title>
Outcome_Check_Check
</title>
<path fill="#f5f5f5" stroke="black" d="M530.52,-62C530.52,-62 382.52,-62 382.52,-62 376.52,-62 370.52,-56 370.52,-50 370.52,-50 370.52,-12 370.52,-12 370.52,-6 376.52,0 382.52,0 382.52,0 530.52,0 530.52,0 536.52,0 542.52,-6 542.52,-12 542.52,-12 542.52,-50 542.52,-50 542.52,-56 536.52,-62 530.52,-62"></path> <text text-anchor="start" x="383.22" y="-37.4" font-family="Helvetica, Arial, sans-serif" font-weight="bold" font-size="14.00">結局 5: 攤牌 (Check-Back)</text> <text text-anchor="start" x="438.43" y="-16.4" font-family="Helvetica, Arial, sans-serif" font-size="14.00">池底: P</text> </g> <!-- B2&#45;&gt;Outcome_Check_Check --> <g id="edge5" class="edge">
<title>
B2-&gt;Outcome_Check_Check
</title>
<path fill="none" stroke="black" d="M271.72,-99.79C297.13,-90.28 330.95,-77.62 362.65,-65.76"></path> <polygon fill="black" stroke="black" points="364.27,-68.89 372.41,-62.1 361.82,-62.33 364.27,-68.89"></polygon> <text text-anchor="middle" x="322.43" y="-93.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 過牌 (Check) </text> </g> <!-- Outcome_Check_Bet_Call --> <g id="node8" class="node">
<title>
Outcome_Check_Bet_Call
</title>
<path fill="#f5f5f5" stroke="black" d="M711.86,-189.6C711.86,-189.6 644.4,-189.6 644.4,-189.6 638.4,-189.6 632.4,-183.6 632.4,-177.6 632.4,-177.6 632.4,-146.4 632.4,-146.4 632.4,-140.4 638.4,-134.4 644.4,-134.4 644.4,-134.4 711.86,-134.4 711.86,-134.4 717.86,-134.4 723.86,-140.4 723.86,-146.4 723.86,-146.4 723.86,-177.6 723.86,-177.6 723.86,-183.6 717.86,-189.6 711.86,-189.6"></path> <text text-anchor="middle" x="678.13" y="-166.2" font-family="Helvetica, Arial, sans-serif" font-size="14.00">結局 3: 攤牌</text> <text text-anchor="middle" x="678.13" y="-149.4" font-family="Helvetica, Arial, sans-serif" font-size="14.00">(池底: P+2B)</text> </g> <!-- A2&#45;&gt;Outcome_Check_Bet_Call --> <g id="edge7" class="edge">
<title>
A2-&gt;Outcome_Check_Bet_Call
</title>
<path fill="none" stroke="black" d="M500.91,-132.31C535.64,-138.16 584.58,-146.41 622.07,-152.72"></path> <polygon fill="black" stroke="black" points="621.88,-156.24 632.32,-154.45 623.05,-149.34 621.88,-156.24"></polygon> <text text-anchor="middle" x="586.64" y="-154.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 跟注 (Call) </text> </g> <!-- Outcome_Check_Bet_Fold --> <g id="node9" class="node">
<title>
Outcome_Check_Bet_Fold
</title>
<path fill="#f5f5f5" stroke="black" d="M713.36,-115.6C713.36,-115.6 642.9,-115.6 642.9,-115.6 636.9,-115.6 630.9,-109.6 630.9,-103.6 630.9,-103.6 630.9,-72.4 630.9,-72.4 630.9,-66.4 636.9,-60.4 642.9,-60.4 642.9,-60.4 713.36,-60.4 713.36,-60.4 719.36,-60.4 725.36,-66.4 725.36,-72.4 725.36,-72.4 725.36,-103.6 725.36,-103.6 725.36,-109.6 719.36,-115.6 713.36,-115.6"></path> <text text-anchor="middle" x="678.13" y="-92.2" font-family="Helvetica, Arial, sans-serif" font-size="14.00">結局 4: B 獲勝</text> <text text-anchor="middle" x="678.13" y="-75.4" font-family="Helvetica, Arial, sans-serif" font-size="14.00">(A 棄牌)</text> </g> <!-- A2&#45;&gt;Outcome_Check_Bet_Fold --> <g id="edge8" class="edge">
<title>
A2-&gt;Outcome_Check_Bet_Fold
</title>
<path fill="none" stroke="black" d="M500.91,-117.69C535.18,-111.91 583.3,-103.81 620.59,-97.53"></path> <polygon fill="black" stroke="black" points="621.52,-100.92 630.8,-95.81 620.36,-94.02 621.52,-100.92"></polygon> <text text-anchor="middle" x="586.64" y="-110.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 棄牌 (Fold) </text> </g> </g>
</svg>
</div>
<figcaption class="figure-caption">Figure&nbsp;1: Full Game Tree: Player B can Bet after A Checks</figcaption>
</figure>
</div>
</div>
</div>
<p>有了之前的經驗，我們知道 Player A 的策略會變成兩個函數 <img src="https://latex.codecogs.com/png.latex?a_1(x),%20a_2(x)">，Player B 的策略也是兩個函數 <img src="https://latex.codecogs.com/png.latex?b_1(y),%20b_2(y)">，</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?a_1(x)">：Player A 在起始點的策略，決定是否下注 (Bet)。</li>
<li><img src="https://latex.codecogs.com/png.latex?b_1(y)">：Player B 在面對 Player A 下注 (A Bet) 時的策略，決定是否跟注 (Call)。</li>
<li><img src="https://latex.codecogs.com/png.latex?b_2(y)">：Player B 在面對 Player A 過牌 (A Check) 時的策略，決定是否偷底 (Bet)。</li>
<li><img src="https://latex.codecogs.com/png.latex?a_2(x)">：Player A 在面對 Player B 偷底 (B Bet) 時的策略，決定是否跟注 (Call)。</li>
</ul>
<p>根據這個設定本身，在 <img src="https://latex.codecogs.com/png.latex?a_1(x)=1"> 時，<img src="https://latex.codecogs.com/png.latex?a_2(x)"> 是多少都不影響結果。所以這本來就是 coupled 的一組策略函數。</p>
</section>
<section id="player-a-的期望值" class="level3">
<h3 class="anchored" data-anchor-id="player-a-的期望值">Player A 的期望值</h3>
<p>遊戲有五種結局，我們寫個表來看看他們分別對 Player A 的 payoff 是多少：</p>
<table class="table">
<colgroup>
<col style="width: 41%">
<col style="width: 18%">
<col style="width: 19%">
<col style="width: 19%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;"></th>
<th style="text-align: center;">若 <img src="https://latex.codecogs.com/png.latex?x%20%3E%20y"></th>
<th style="text-align: center;">若 <img src="https://latex.codecogs.com/png.latex?x%20=%20y"></th>
<th style="text-align: center;">若 <img src="https://latex.codecogs.com/png.latex?x%20%3C%20y"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">結局 1 (A bet, B call)</td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P+B"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P/2"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?-B"></td>
</tr>
<tr class="even">
<td style="text-align: center;">結局 2 (A bet, B fold)</td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P"></td>
</tr>
<tr class="odd">
<td style="text-align: center;">結局 3 (A check, B bet, A call)</td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P+B"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P/2"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?-B"></td>
</tr>
<tr class="even">
<td style="text-align: center;">結局 4 (A check, B bet, A fold)</td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?0"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?0"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?0"></td>
</tr>
<tr class="odd">
<td style="text-align: center;">結局 5 (A check, B check)</td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?P/2"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?0"></td>
</tr>
</tbody>
</table>
<p>同樣的，我們忽略相等的情況 (機率為零)，然後寫一下機率密度:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Barray%7D%7B%7Cl%7Cc%7Cc%7Cl%7C%7D%0A%5Chline%0A%5Ctextbf%7B%E7%B5%90%E5%B1%80%E8%B7%AF%E5%BE%91%7D%20&amp;%20%5Ctextbf%7B%E8%8B%A5%20%7D%20x%20%3E%20y%20&amp;%20%5Ctextbf%7B%E8%8B%A5%20%7D%20x%20%3C%20y%20&amp;%20%5Ctextbf%7B%E6%A9%9F%E7%8E%87%E5%AF%86%E5%BA%A6%7D%20%5C%5C%0A%5Chline%0A%5Ctext%7B1.%20A%20Bet,%20B%20Call%7D%20&amp;%20P+B%20&amp;%20-B%20&amp;%20a_1(x)%20%5Ccdot%20b_1(y)%20%5C%5C%0A%5Chline%0A%5Ctext%7B2.%20A%20Bet,%20B%20Fold%7D%20&amp;%20P%20&amp;%20P%20&amp;%20a_1(x)%20%5Ccdot%20(1%20-%20b_1(y))%20%5C%5C%0A%5Chline%0A%5Ctext%7B3.%20A%20Check,%20B%20Bet,%20A%20Call%7D%20&amp;%20P+B%20&amp;%20-B%20&amp;%20(1%20-%20a_1(x))%20%5Ccdot%20b_2(y)%20%5Ccdot%20a_2(x)%20%5C%5C%0A%5Chline%0A%5Ctext%7B4.%20A%20Check,%20B%20Bet,%20A%20Fold%7D%20&amp;%200%20&amp;%200%20&amp;%20(1%20-%20a_1(x))%20%5Ccdot%20b_2(y)%20%5Ccdot%20(1%20-%20a_2(x))%20%5C%5C%0A%5Chline%0A%5Ctext%7B5.%20A%20Check,%20B%20Check%7D%20&amp;%20P%20&amp;%200%20&amp;%20(1%20-%20a_1(x))%20%5Ccdot%20(1%20-%20b_2(y))%20%5C%5C%0A%5Chline%0A%5Cend%7Barray%7D%0A"></p>
<p>接著利用這張表，我們將各結局的「機率密度」與「損益」相乘，並對所有可能的牌型 <img src="https://latex.codecogs.com/png.latex?x,%20y"> 積分，即可寫出 Player A 的期望值函數。</p>
<p>我將第 4 項（結局 4）省略了，因為其損益為 0，對積分沒有貢獻。</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A&amp;%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_A%5D%20:=%20%5Cmathcal%7BL%7D(a_1,%20a_2,%20b_1,%20b_2)%20%5C%5C%0A&amp;=%20%5Cint_0%5E1%20%5Cint_0%5E1%20%5CBigg%5B%20%5C%5C%0A&amp;%5Cquad%20a_1(x)%20%5Ccdot%20b_1(y)%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%0A&amp;%5Cqquad%5Ctext%7B(%E7%B5%90%E5%B1%80%201:%20A%20Bet,%20B%20Call)%7D%20%5C%5C%0A&amp;%5Cquad%20+%20a_1(x)%20%5Ccdot%20(1%20-%20b_1(y))%20%5Ccdot%20P%0A&amp;%5Cqquad%5Ctext%7B(%E7%B5%90%E5%B1%80%202:%20A%20Bet,%20B%20Fold)%7D%20%5C%5C%0A&amp;%5Cquad%20+%20(1%20-%20a_1(x))%20%5Ccdot%20b_2(y)%20%5Ccdot%20a_2(x)%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%0A&amp;%5Cqquad%5Ctext%7B(%E7%B5%90%E5%B1%80%203:%20A%20Check,%20B%20Bet,%20A%20Call)%7D%20%5C%5C%0A&amp;%5Cquad%20+%20(1%20-%20a_1(x))%20%5Ccdot%20(1%20-%20b_2(y))%20%5Ccdot%20P%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%0A&amp;%5Cqquad%5Ctext%7B(%E7%B5%90%E5%B1%80%205:%20A%20Check,%20B%20Check)%7D%20%5C%5C%0A&amp;%5Cquad%20%5CBigg%5D%20dy%20%5C,%20dx%0A%5Cend%7Baligned%7D%0A"></p>
</section>
<section id="四個函數的變分" class="level2">
<h2 class="anchored" data-anchor-id="四個函數的變分">四個函數的變分</h2>
<p>我們從最裡面解回來，也就是說，我們先假設 <img src="https://latex.codecogs.com/png.latex?a_1(x),%20b_1(y),%20b_2(y)"> 已經定好了，然後我們來找出最佳的 <img src="https://latex.codecogs.com/png.latex?a_2(x)"> 來最大化 Lagrangian。</p>
<p><strong>解 <img src="https://latex.codecogs.com/png.latex?a_2(x)">:</strong></p>
<p>只需要考慮包含 <img src="https://latex.codecogs.com/png.latex?a_2(x)"> 的項: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A&amp;%5Cint_0%5E1%20%5Cint_0%5E1%20(1%20-%20a_1(x))%20%5Ccdot%20b_2(y)%20%5Ccdot%20%5Ctextcolor%7Bred%7D%7Ba_2(x)%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20%20dy%20%5C,%20dx%20%20%5C%5C%0A=%20&amp;%5Cint_0%5E1%20(1%20-%20a_1(x))%20%5Ccdot%20%5Ctextcolor%7Bred%7D%7Ba_2(x)%7D%20%5Ccdot%20%20%5Cunderbrace%7B%20%5Cleft(%20%5Cint_0%5E1%20b_2(y)%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20dy%20%5Cright)%7D_%7Bg(x)%7D%20%20dx%20%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>符合剛才的直覺，當 <img src="https://latex.codecogs.com/png.latex?a_1(x)=1"> 時，<img src="https://latex.codecogs.com/png.latex?a_2(x)"> 不影響結果。</p>
<p>這個 <img src="https://latex.codecogs.com/png.latex?g(x)"> 的形式跟我們上一篇中的 <img src="https://latex.codecogs.com/png.latex?h(y)"> 幾乎一樣。這也很合理，因為我們從最後一步開始解，而上一次就是單純解最後一步。</p>
<p>來快速算一下這個 <img src="https://latex.codecogs.com/png.latex?g(x)">: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Ag(0)%20&amp;=%20-B%20%5Ccdot%20%5Cint_0%5E1%20b_2(y)%20dy%20%5C%5C%0Ag(1)%20&amp;=%20(P+B)%20%5Ccdot%20%5Cint_0%5E1%20b_2(y)%20dy%20%5C%5C%0Ag(x)'%20&amp;=%20(P%20+%202B)%20%5Ccdot%20b_2(x)%20%5Cgeq%200%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>這個 <img src="https://latex.codecogs.com/png.latex?g(x)"> 是從負值遞增，然後過零點，最後變成正值的函數。</p>
<p>那麼 <img src="https://latex.codecogs.com/png.latex?a_2(x)"> 就是 <img src="https://latex.codecogs.com/png.latex?%0Aa_2(x)%20=%20%5Cbegin%7Bcases%7D%0A0,%20&amp;%20g(x)%20%3C%200%20%5C%5C%0A1,%20&amp;%20g(x)%20%3E%200%20%5C%5C%0A%5Ctext%7BAny%7D,%20&amp;%20(1-a_1(x))%20%5Ccdot%20g(x)%20=%200%20%5C%5C%0A%5Cend%7Bcases%7D%0A"> 既然其他點可以取任意值，不妨假設 <img src="https://latex.codecogs.com/png.latex?%0Aa_2(x)%20=%20%5Cmathbb%7B1%7D_%7Bx%20%3E%20x_2%5E*%7D%20%20%5Ctag%7B1%7D%5Clabel%7Beq:a2-strategy%7D%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 是使 <img src="https://latex.codecogs.com/png.latex?g(x_2%5E*)=0"> 的解。也就是 <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cint_0%5E%7Bx_2%5E*%7D%20b_2(y)%20dy%7D%7B%5Cint_%7Bx_2%5E*%7D%5E1%20b_2(y)%20dy%7D%20=%20%5Cfrac%7BB%7D%7BP+B%7D%20%20%5Ctag%7B2%7D%5Clabel%7Beq:x2-ratio%7D%0A"></p>
<p>解出 <img src="https://latex.codecogs.com/png.latex?a_2(x)"> 後，接著解 <img src="https://latex.codecogs.com/png.latex?b_1(y)"> 或 <img src="https://latex.codecogs.com/png.latex?b_2(y)"> 都可以。因為沒有相依性。</p>
<p><strong>解 <img src="https://latex.codecogs.com/png.latex?b_1(x)">:</strong></p>
<p>只需要考慮包含 <img src="https://latex.codecogs.com/png.latex?b_1(y)"> 的項: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A&amp;%5Cint_0%5E1%20%5Cint_0%5E1%20a_1(x)%20%5Ccdot%20%5Ctextcolor%7Bred%7D%7Bb_1(y)%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20-P%20%5CBig)%20%20dy%20%5C,%20dx%20%20%5C%5C%0A=%20&amp;%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Bb_1(y)%7D%20%5Ccdot%20%5Cunderbrace%7B%20%5Cleft(%20%5Cint_0%5E1%20a_1(x)%20%5CBig(%20B%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20dx%20%5Cright)%7D_%7Bh(y)%7D%20%20dy%20%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 再來一次， <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Ah(0)%20&amp;=%20B%20%5Ccdot%20%5Cint_0%5E1%20a_1(x)%20dx%20%5C%5C%0Ah(1)%20&amp;=%20-(P+B)%20%5Ccdot%20%5Cint_0%5E1%20a_1(x)%20dx%20%5C%5C%0Ah(y)'%20&amp;=%20-(P+2B)%20%5Ccdot%20a_1(y)%20%5Cleq%200%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 而 <img src="https://latex.codecogs.com/png.latex?b_1(y)"> 要最小化它，所以存在一個切分點 <img src="https://latex.codecogs.com/png.latex?y_1%5E*"> 使得 <img src="https://latex.codecogs.com/png.latex?%0Ab_1(y)%20=%20%5Cmathbb%7B1%7D_%7By%20%3E%20y_1%5E*%7D%20%20%5Ctag%7B3%7D%5Clabel%7Beq:b1-strategy%7D%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?y_1%5E*"> 是使 <img src="https://latex.codecogs.com/png.latex?h(y_1%5E*)=0"> 的解。也就是 <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cint_0%5E%7By_1%5E*%7D%20a_1(x)%20dx%7D%7B%5Cint_%7By_1%5E*%7D%5E1%20a_1(x)%20dx%7D%20=%20%5Cfrac%7BB%7D%7BP+B%7D%20%20%5Ctag%7B4%7D%5Clabel%7Beq:y1-ratio%7D%0A"> 這邊確實就跟上一篇一模一樣了，因為上一篇也有這個分支。</p>
<p><strong>解 <img src="https://latex.codecogs.com/png.latex?b_2(y)">:</strong></p>
<p>考慮包含 <img src="https://latex.codecogs.com/png.latex?b_2(y)"> 的項，此時把剛剛解的 <img src="https://latex.codecogs.com/png.latex?a_2(x)"> 帶進去: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A&amp;%5Cint_0%5E1%20%5Cint_0%5E1%20(1%20-%20a_1(x))%20%5Ccdot%20%5Ctextcolor%7Bred%7D%7Bb_2(y)%7D%20%5Ccdot%20%5CBig%5B%20%5Cmathbb%7B1%7D_%7Bx%20%3E%20x_2%5E*%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20-%20P%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20%20%5CBig%5D%20%20dy%20%5C,%20dx%20%20%5C%5C%0A=%20&amp;%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Bb_2(y)%7D%20%5Ccdot%20%5Cleft(%20%5Cint_0%5E1%20(1%20-%20a_1(x))%20%5Ccdot%20%5CBig%5B%20%5Cmathbb%7B1%7D_%7Bx%20%3E%20x_2%5E*%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20-%20P%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20%20%5CBig%5D%20dx%20%5Cright)%20%20dy%20%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 這邊稍微複雜一點，因為 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 其實是根據 <img src="https://latex.codecogs.com/png.latex?b_2(y)"> 決定的 (依照切分比例)。所以不能將 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 當成常數來看待。</p>
<p>交換一下順序，我們假設 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 是固定的，現在將 <img src="https://latex.codecogs.com/png.latex?b_2(y)"> 拆成兩個區間來做變分，但有面積的條件: <img src="https://latex.codecogs.com/png.latex?%0A%5Cint_0%5E%7Bx_2%5E*%7D%20b_2(y)%20dy%20:%20%5Cint_%7Bx_2%5E*%7D%5E1%20b_2(y)%20dy%20=%20B%20:%20(P+B)%0A"> 所以上面變成 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A&amp;%5Cint_0%5E%7B1%7D%20%5Ctextcolor%7Bred%7D%7Bb_2(y)%7D%20%5Ccdot%20%5Cleft(%20%5Cint_0%5E1%20(1%20-%20a_1(x))%20%5Ccdot%20%5CBig%5B%20%5Cmathbb%7B1%7D_%7Bx%20%3E%20x_2%5E*%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20-%20P%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20%20%5CBig%5D%20dx%20%5Cright)%20%20dy%20%5C%5C%0A=%20&amp;%5Cint_0%5E%7Bx_2%5E*%7D%20%5Ctextcolor%7Bred%7D%7Bb_2(y)%7D%20%5Ccdot%20%5Cunderbrace%7B%5Cleft(%20%5Cint_0%5E1%20(1%20-%20a_1(x))%20%5Ccdot%20%5CBig%5B%20(P+B)%5Cmathbb%7B1%7D_%7Bx%20%3E%20x_2%5E*%7D%20-%20P%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20%20%5CBig%5D%20dx%20%5Cright)%7D_%7Bk_1(y)%7D%20%20dy%20%5C%5C%0A&amp;+%20%5Cint_%7Bx_2%5E*%7D%5E%7B1%7D%20%5Ctextcolor%7Bred%7D%7Bb_2(y)%7D%20%5Ccdot%20%5Cunderbrace%7B%5Cleft(%20%5Cint_0%5E1%20(1%20-%20a_1(x))%20%5Ccdot%20%5CBig%5B%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Ex_2%5E*%7D%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20-%20P%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20%20%5CBig%5D%20dx%20%5Cright)%7D_%7Bk_2(y)%7D%20%20dy%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 如此一來又變回熟悉的形式了。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Ak_1(0)%20&amp;=%20(P+B)%20%5Ccdot%20%5Cint_%7Bx_2%5E*%7D%5E1%20(1%20-%20a_1(x))%20dx%20-%20P%20%5Ccdot%20%5Cint_0%5E1%20(1%20-%20a_1(x))%20dx%20%5C%5C%0A&amp;=%20B%20%5Ccdot%20%5Cint_%7Bx_2%5E*%7D%5E1%20(1%20-%20a_1(x))%20dx%20-%20P%20%5Ccdot%20%5Cint_0%5E%7Bx_2%5E*%7D%20(1%20-%20a_1(x))%20dx%20%5C%5C%0Ak_1(x_2%5E*)%20&amp;=%20B%20%5Ccdot%20%5Cint_%7Bx_2%5E*%7D%5E1%20(1%20-%20a_1(x))%20dx%20%5Cgeq%200%20%20%5C%5C%0Ak_1(y)'%20&amp;=%20P%20%5Ccdot%20(1%20-%20a_1(y))%20%5Cgeq%200%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 以及 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Ak_2(x_2%5E*)%20&amp;=%20B%20%5Ccdot%20%5Cint_%7Bx_2%5E*%7D%5E1%20(1%20-%20a_1(x))%20dx%20%5Cgeq%200%20%5C%5C%0Ak_2(1)%20&amp;=%20-B%20%5Ccdot%20%5Cint_%7Bx_2%5E*%7D%5E1%20(1%20-%20a_1(x))%20dx%20%5Cleq%200%20%5C%5C%0Ak_2(y)'%20&amp;=%20-2B%20%5Ccdot%20(1-a_1(y))%20%5Cleq%200%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 因此， <img src="https://latex.codecogs.com/png.latex?k_2(y),%20k_1(y)"> 這兩個函數，分別是遞增與遞減，而 <img src="https://latex.codecogs.com/png.latex?b_2(y)"> 要最小化整個式子，所以 <img src="https://latex.codecogs.com/png.latex?b_2(y)"> 是極化的策略 (不妨假設<img src="https://latex.codecogs.com/png.latex?k_1(0)%3C0">，否則的話就取 <img src="https://latex.codecogs.com/png.latex?z_1%5E*=0"> 即可，我們要解的是形狀): <img src="https://latex.codecogs.com/png.latex?%0Ab_2(y)%20=%20%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20+%20%5Cmathbb%7B1%7D_%7By%20%3E%20z_2%5E*%7D%20%20%5Ctag%7B5%7D%5Clabel%7Beq:b2-strategy%7D%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?z_1%5E*,%20z_2%5E*"> 是使得 <img src="https://latex.codecogs.com/png.latex?k_1(z_1%5E*)=0,%20k_2(z_2%5E*)=0"> 的解。</p>
<p>假設確實有 <img src="https://latex.codecogs.com/png.latex?k_1(0)%3C0">，那麼 <img src="https://latex.codecogs.com/png.latex?%0A%5Cint_%7Bz_1%5E*%7D%5E%7Bx_2%5E*%7D%20(1%20-%20a_1(x))%20dx%20=%20%5Cfrac%7BB%7D%7BP%7D%20%5Ccdot%20%5Cint_%7Bx_2%5E*%7D%5E1%20(1%20-%20a_1(x))%20dx%20%20%5Ctag%7B6%7D%5Clabel%7Beq:z1-ratio%7D%0A"> 以及 <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cint_%7Bx_2%5E*%7D%5E%7Bz_2%5E*%7D%20(1%20-%20a_1(x))%20dx%7D%7B%5Cint_%7Bz_2%5E*%7D%5E1%20(1%20-%20a_1(x))%20dx%7D%20=%20%5Cfrac%7Bk_2(x_2%5E*)%7D%7B-k_2(1)%7D%20=%20%5Cfrac%7BB%7D%7BB%7D%20=%201%20%20%5Ctag%7B7%7D%5Clabel%7Beq:z2-ratio%7D%0A"> 因此， <img src="https://latex.codecogs.com/png.latex?z_1%5E*,%20z_2%5E*"> 是依照 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 定義的。</p>
<p>等等，還有面積的條件需要滿足。但已經沒有自由度可以用了。也就是說最好的 <img src="https://latex.codecogs.com/png.latex?b_2(y)%20=%20%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20+%20%5Cmathbb%7B1%7D_%7By%20%3E%20z_2%5E*%7D"> 並不一定滿足面積比是 <img src="https://latex.codecogs.com/png.latex?B:P+B"> 這個條件。</p>
<p>但我們現在假設 Player A 固定，所以 <img src="https://latex.codecogs.com/png.latex?a_2(x)"> 是固定的。所以理解為，我們猜測 <img src="https://latex.codecogs.com/png.latex?a_2(x)"> 的形狀，在這樣條件下來看 <img src="https://latex.codecogs.com/png.latex?b_1(y),%20b_2(y)"> 可以打出的最佳進攻策略是什麼，而不需要滿足面積條件 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:x2-ratio%7D"> 。所以以上的推導依然成立。</p>
<p><strong>解 <img src="https://latex.codecogs.com/png.latex?a_1(x)">:</strong></p>
<p>這邊解 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 有兩種視角:</p>
<ol type="1">
<li><strong>最佳進攻策略</strong>: 對於任意<strong>固定</strong>函數 <img src="https://latex.codecogs.com/png.latex?b_1(y),%20b_2(y)">，我們來看如何攻擊這組 <img src="https://latex.codecogs.com/png.latex?b_1,%20b_2"> (最大化 Lagrangian)。但上面的討論告訴我們，我們不用解最一般的情形，可以假設它的形狀是 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:b1-strategy%7D">, <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:b2-strategy%7D">。</li>
<li><strong>最佳防守策略</strong>: 將上面解出的 <img src="https://latex.codecogs.com/png.latex?b_1(y),%20b_2(y)"> 帶回 Lagrangian，然後解 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 來最大化 Lagrangian，也就是被 Player B 已知 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 的情形之下，要如何防守的概念，因為這裡 <img src="https://latex.codecogs.com/png.latex?b_1(y),%20b_2(y)"> <strong>可以</strong>隨著 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 改變而改變。</li>
</ol>
<p>這兩種視角都挺重要的，也都有意義。但因為 Nash Equilibrium 是在講最佳防守，所以我們先用第二種視角來看。</p>
<p>如果從 Player A 的防守視角來看，當固定 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 和 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 且被 Player B 已知的情形下，Player B 對於 <img src="https://latex.codecogs.com/png.latex?b_1(y),%20b_2(y)"> 的最佳攻擊策略是什麼? 利用 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:b1-strategy%7D">, <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:b2-strategy%7D">，我們將期約化為三個變數:</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?y_1%5E*">: 把 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 底下的面積切成 <img src="https://latex.codecogs.com/png.latex?B%20:%20(P+B)"> 的比例。</li>
<li><img src="https://latex.codecogs.com/png.latex?z_1%5E*,%20z_2%5E*">: 先從 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 切開，然後選擇 <img src="https://latex.codecogs.com/png.latex?z_1%5E*"> 滿足 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z1-ratio%7D">，接著選擇 <img src="https://latex.codecogs.com/png.latex?z_2%5E*"> 滿足 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z2-ratio%7D">。</li>
</ul>
<p>這樣確實是 Player B 對 Player A 最嚴厲的攻擊。但有個風險，因為沒有滿足 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:x2-ratio%7D">，所以如果 Player A 改變 <img src="https://latex.codecogs.com/png.latex?x_2%5E*">，就可以對 Player B 進行剝削。(至於這一來一往是正的還是負的? 感覺不好估計)</p>
<p>我們換個角度想，Player B 能不能選 <img src="https://latex.codecogs.com/png.latex?z_1%5E*,%20z_2%5E*"> 使得就算 Player A 改變 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 也不會被剝削?</p>
<p>也就是要把 <img src="https://latex.codecogs.com/png.latex?z_1%5E*,%20z_2%5E*"> 選成跟 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 無關的形式。回頭看看 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z1-ratio%7D">, <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z2-ratio%7D">，我們發現只要滿足下面的條件就可以了: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bcases%7D%0A%5Cdisplaystyle%20%5Cint_%7B%5Ctextcolor%7Bred%7D%7Bz_1%5E*%7D%7D%5E%7B%5Ctextcolor%7Bred%7D%7Bz_2%5E*%7D%7D%20(1%20-%20a_1(x))%20dx%20:%20%5Cint_%7B%5Ctextcolor%7Bred%7D%7Bz_2%5E*%7D%7D%5E1%20(1%20-%20a_1(x))%20dx%20=%20(B%20+%20%5Cfrac%7BP%7D%7B2%7D)%20:%20%5Cfrac%7BP%7D%7B2%7D%20%20%20%5C%5C%0A%5Cdisplaystyle%20%5Ctextcolor%7Bred%7D%7Bz_1%5E*%7D%20:%20(1%20-%20%5Ctextcolor%7Bred%7D%7Bz_2%5E*%7D)%20=%20B%20:%20(P+B)%0A%5Cend%7Bcases%7D%20%5Ctag%7B8%7D%5Clabel%7Beq:z1z2-equations%7D%0A"> 這邊很巧妙把 <img src="https://latex.codecogs.com/png.latex?B:P"> 和 <img src="https://latex.codecogs.com/png.latex?1:1">，變成了 <img src="https://latex.codecogs.com/png.latex?B%20+%20%5Cfrac%7BP%7D%7B2%7D%20:%20%5Cfrac%7BP%7D%7B2%7D">，如此一來就跟 <img src="https://latex.codecogs.com/png.latex?x_2%5E*"> 無關，而多出來的自由度可以讓 Player B 調整 <img src="https://latex.codecogs.com/png.latex?z_1%5E*,%20z_2%5E*"> 來滿足面積條件 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:x2-ratio%7D">。</p>
<p>這邊有點一直交換 Min-Max的順序來論證，應該是對的。</p>
<p>現在我們得到小結論，Player B 只要知道 <img src="https://latex.codecogs.com/png.latex?a_1(x)">，就可以選出一組 <img src="https://latex.codecogs.com/png.latex?b_1(y),%20b_2(y)"> (也就是 <img src="https://latex.codecogs.com/png.latex?y_1%5E*,%20z_1%5E*,%20z_2%5E*">) 來攻擊 Player A。</p>
<p>所以問題已經約化到只剩最後一個函數: <img src="https://latex.codecogs.com/png.latex?a_1(x)">，要取多少可以最大化 Lagrangian。</p>
<p>先來看看完整的 Lagrangian，我們先在沒有 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z1z2-equations%7D"> 約束下解，也就是這邊的等式對於一般的 <img src="https://latex.codecogs.com/png.latex?y_1%5E*,%20z_1%5E*,%20z_2%5E*"> 都成立 (順便研究 Player A 的攻擊策略): <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cmathcal%7BL%7D(a_1,%20a_2,%20b_1,%20b_2)%20%20%5C%5C%0A&amp;=%20%5Cint_0%5E1%20%5Cint_0%5E1%0A%5Cleft%5B%0A%5Cbegin%7Baligned%7D%0A%20%20%20%20&amp;%20a_1(x)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7By%3Ey_1%5E*%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20%5C%5C%0A%20%20%20%20+%20&amp;%20a_1(x)%20%5Ccdot%20(1%20-%20%5Cmathbb%7B1%7D_%7By%3Ey_1%5E*%7D)%20%5Ccdot%20P%20%5C%5C%0A%20%20%20%20+%20&amp;%20(1%20-%20a_1(x))%20%5Ccdot%20(%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20+%20%5Cmathbb%7B1%7D_%7By%20%3E%20z_2%5E*%7D)%20%5Ccdot%20(%5Cmathbb%7B1%7D_%7Bx%3Ex_2%5E*%7D)%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20%5C%5C%0A%20%20%20%20+%20&amp;%20(1%20-%20a_1(x))%20%5Ccdot%20(1%20-%20%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20-%20%5Cmathbb%7B1%7D_%7By%20%3E%20z_2%5E*%7D)%20%5Ccdot%20P%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%0A%5Cend%7Baligned%7D%0A%5Cright%5D%20dy%20%5C,%20dx%20%20%5C%5C%0A&amp;=%20%20%5Cint_0%5E1%20%5Cint_0%5E1%20%5Cunderbrace%7B%5CBig%5B%20(%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20+%20%5Cmathbb%7B1%7D_%7By%20%3E%20z_2%5E*%7D)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ex_2%5E*%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20+%20(1%20-%20%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20-%20%5Cmathbb%7B1%7D_%7By%20%3E%20z_2%5E*%7D)%20%5Ccdot%20P%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20%5CBig%5D%7D_%7BJ(x,y)%7D%20dy%20%5C,%20dx%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Ba_1(x)%7D%20%5Ccdot%20%5Cunderbrace%7B%5Cleft(%20%5Cint_0%5E1%0A%5Cleft%5B%0A%5Cbegin%7Baligned%7D%0A%20%20%20%20&amp;%20%5Cmathbb%7B1%7D_%7By%3Ey_1%5E*%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20+%20(1%20-%20%5Cmathbb%7B1%7D_%7By%3Ey_1%5E*%7D)%20%5Ccdot%20P%20%5C%5C%0A%20%20%20%20&amp;%20-%20(%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20+%20%5Cmathbb%7B1%7D_%7By%20%3E%20z_2%5E*%7D)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ex_2%5E*%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5CBig)%20%5C%5C%0A%20%20%20%20&amp;%20-%20(1%20-%20%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20-%20%5Cmathbb%7B1%7D_%7By%20%3E%20z_2%5E*%7D)%20%5Ccdot%20P%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%0A%5Cend%7Baligned%7D%0A%5Cright%5D%20dy%20%5Cright)%7D_%7BG(x)%7D%20dx%0A%5Cend%7Balign%7D%0A"> 有些些混亂，我們把大於的符號一律改成小於的方向，看比較清楚。</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmathcal%7BL%7D(a_1,%20a_2,%20b_1,%20b_2)%20&amp;=%20%5Cint_0%5E1%20%5Cint_0%5E1%20J(x,y)%20%5C,%20dy%20%5C,%20dx%20+%20%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Ba_1(x)%7D%20%5Ccdot%20G(x)%20%5C,%20dx%20%5C%5C%0A%5Ctext%7B%E5%85%B6%E4%B8%AD%7D%20%5Cquad%0AJ(x,y)%20&amp;=%20(%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20+%20%5Cmathbb%7B1%7D_%7Bz_2%5E*%20%3C%20y%7D)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx_2%5E*%20%3C%20x%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7By%20%3C%20x%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%20%3C%20y%7D%20%5CBig)%20+%20%5Cmathbb%7B1%7D_%7Bz_1%5E*%20%5Cle%20y%20%5Cle%20z_2%5E*%7D%20%5Ccdot%20P%20%5Cmathbb%7B1%7D_%7By%20%3C%20x%7D%20%5C%5C%0AG(x)%20&amp;=%20%5Cint_0%5E1%0A%5Cleft%5B%0A%5Cbegin%7Baligned%7D%0A%20%20%20%20&amp;%20%5Cmathbb%7B1%7D_%7By_1%5E*%20%3C%20y%7D%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7By%20%3C%20x%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%20%3C%20y%7D%20%5CBig)%20+%20P%20%5Cmathbb%7B1%7D_%7By%20%5Cle%20y_1%5E*%7D%20%5C%5C%0A%20%20%20%20&amp;%20-%20%5Cmathbb%7B1%7D_%7Bx_2%5E*%20%3C%20x%7D%20%5Ccdot%20(%5Cmathbb%7B1%7D_%7By%20%3C%20z_1%5E*%7D%20+%20%5Cmathbb%7B1%7D_%7Bz_2%5E*%20%3C%20y%7D)%20%5Ccdot%20%5CBig(%20(P+B)%5Cmathbb%7B1%7D_%7By%20%3C%20x%7D%20-%20B%5Cmathbb%7B1%7D_%7Bx%20%3C%20y%7D%20%5CBig)%20%5C%5C%0A%20%20%20%20&amp;%20-%20P%20%5Cmathbb%7B1%7D_%7Bz_1%5E*%20%5Cle%20y%20%5Cle%20z_2%5E*%7D%20%5Ccdot%20%5Cmathbb%7B1%7D_%7By%20%3C%20x%7D%0A%5Cend%7Baligned%7D%0A%5Cright%5D%20dy%0A%5Cend%7Balign%7D%0A"> 好，雖然有點小複雜，但這都是 indicator function，積分通常可以直接算出來。</p>
<div id="fig-jxy-region" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/poker/images/lesson_7/integral_region_Jxy.png" class="img-fluid figure-img"></p>
<figcaption class="figure-caption">Figure&nbsp;2: <img src="https://latex.codecogs.com/png.latex?J(x,y)"> Integral Region</figcaption>
</figure>
</div>
<p>我們先假設有 <img src="https://latex.codecogs.com/png.latex?z_1%5E*%20%5Cleq%20x_2%5E*%20%5Cleq%20z_2%5E*">， <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cint_0%5E1%20%5Cint_0%5E1%20J(x,y)%20%5C,%20dy%20%5C,%20dx%0A&amp;=%20P%5Ccdot%20(z_2%5E*%20-%20z_1%5E*)(1-%5Cfrac%7Bz_2%5E*%20+%20z_1%5E*%7D%7B2%7D)%20%5C%5C%0A&amp;%5Cquad%20+%20(P+B)%5Ccdot%20%5Cleft(%20%5Cfrac%7B(1-z_2%5E*)%5E2%7D%7B2%7D%20+%20z_1%5E*(1-x_2%5E*)%20%5Cright)%20%5C%5C%0A&amp;%5Cquad%20-%20B%20%5Ccdot%20(1-z_2%5E*)(%5Cfrac%7B1+z_2%5E*%7D%7B2%7D%20-%20x_2%5E*)%20%5C%5C%0A&amp;=%20P%20%5Ccdot%20%5Cleft%5B%20%5Cfrac%7B(1-z_1%5E*)%5E2%7D%7B2%7D%20+%20z_1%5E*(1-x_2%5E*)%20%5Cright%5D%20+%20B%20%5Ccdot%20%5Cleft%5B%20z_1%5E*(1-x_2%5E*)%20-%20(1-z_2%5E*)(z_2%5E*%20-%20x_2%5E*)%20%5Cright%5D%0A%5Cend%7Baligned%7D%0A"></p>
<p>已經有點醜了，再來試試看 <img src="https://latex.codecogs.com/png.latex?G(x)">，注意到積分後半段跟剛才的 <img src="https://latex.codecogs.com/png.latex?J(x,y)"> 其實一樣，然後前半段相對簡單。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0AG(x)%20&amp;=%20%5Cunderbrace%7B%0A%5Cbegin%7Bcases%7D%0A(P+B)y_1%5E*%20-%20B%20&amp;%20%5Ctext%7Bif%20%7D%20x%20%5Cle%20y_1%5E*%20%5C%5C%0A(P+2B)x%20-%20B(1+y_1%5E*)%20&amp;%20%5Ctext%7Bif%20%7D%20x%20%3E%20y_1%5E*%0A%5Cend%7Bcases%7D%0A%7D_%7B%5Ctext%7BPart%201:%20%7D%20y_1%5E*%20%5Ctext%7B%20Dependent%20Terms%7D%7D%20%5C%5C%0A&amp;%5Cqquad%20+%0A%5Cunderbrace%7B%0A%5Cbegin%7Bcases%7D%0A0%20&amp;%20%5Ctext%7Bif%20%7D%20x%20%3C%20z_1%5E*%20%5C%5C%0A-P(x%20-%20z_1%5E*)%20&amp;%20%5Ctext%7Bif%20%7D%20z_1%5E*%20%5Cle%20x%20%5Cle%20x_2%5E*%20%5C%5C%0A-Px%20+%20B(1%20-%20z_1%5E*%20-%20z_2%5E*)%20&amp;%20%5Ctext%7Bif%20%7D%20x_2%5E*%20%3C%20x%20%3C%20z_2%5E*%20%5C%5C%0A-(P+2B)x%20+%20B(1%20-%20z_1%5E*%20+%20z_2%5E*)%20&amp;%20%5Ctext%7Bif%20%7D%20x%20%5Cge%20z_2%5E*%0A%5Cend%7Bcases%7D%0A%7D_%7B%5Ctext%7BPart%202:%20%7D%20z_1%5E*,%20x_2%5E*,%20z_2%5E*%20%5Ctext%7B%20Dependent%20Terms%7D%7D%20%20%5Ctag%7B9%7D%5Clabel%7Beq:Gx-pieces%7D%0A%5Cend%7Balign%7D%0A"></p>
<p>其實還不算是太醜(?)，基本上是由折線線段組成的，但在第二項 <img src="https://latex.codecogs.com/png.latex?x=x_2%5E*"> 有個(可能)不連續的點。而這個點若要連續，就是要滿足面積比例的條件!! <img src="https://latex.codecogs.com/png.latex?%0Az_1%5E*%20:%20(1-z_2%5E*)%20=%20B%20:%20(P+B)%0A"></p>
<p>現在我們使用 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z1z2-equations%7D"> 的條件，所以以下結果開始基於有面積比例的條件。</p>
<p><img src="https://latex.codecogs.com/png.latex?J(x,y)"> 積分變得好看很多，而 <img src="https://latex.codecogs.com/png.latex?G(x)"> 第二項也會連續。因為前後兩段斜率相同，所以會直接變一段。</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cint_0%5E1%20%5Cint_0%5E1%20J(x,y)%20%5C,%20dy%20%5C,%20dx%20=%20%20%5Cfrac%7BP%7D%7B2%7D(1-z_1%5E*)%5E2%20+%20B(1-z_2%5E*)%5E2%20%20%5Ctag%7B10%7D%5Clabel%7Beq:Jxy-integral-with-constraints%7D%0A"> <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0AG_1(x)%20&amp;=%20%5Cbegin%7Bcases%7D%0A(P+B)y_1%5E*%20-%20B%20&amp;%20%5Ctext%7B,%20if%20%7D%20x%20%5Cle%20y_1%5E*%20%5C%5C%0A(P+2B)x%20-%20B(1+y_1%5E*)%20&amp;%20%5Ctext%7B,%20if%20%7D%20x%20%3E%20y_1%5E*%0A%5Cend%7Bcases%7D%20%20%5Ctag%7B11%7D%5Clabel%7Beq:G1x%7D%20%5C%5C%0AG_2(x)%20&amp;=%0A%5Cbegin%7Bcases%7D%0A0%20&amp;%20%5Ctext%7B,%20if%20%7D%20x%20%3C%20z_1%5E*%20%5C%5C%0AP(x%20-%20z_1%5E*)%20&amp;%20%5Ctext%7B,%20if%20%7D%20z_1%5E*%20%5Cle%20x%20%5Cle%20z_2%5E*%20%5C%5C%0A(P+2B)(x+z_1%5E*)%20-%202B%20&amp;%20%5Ctext%7B,%20if%20%7D%20x%20%5Cge%20z_2%5E*%0A%5Cend%7Bcases%7D%20%20%5Ctag%7B12%7D%5Clabel%7Beq:G2x%7D%20%5C%5C%0AG(x)%20&amp;=%20G_1(x)%20-%20G_2(x)%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 我們把 <img src="https://latex.codecogs.com/png.latex?G"> 拆分成兩個，第二個加了負號，這樣一來斜率都是正的了。還有做了一些簡單的代數代換，讀者可自行驗證。</p>
<div id="fig-plot-G1-G2" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/poker/images/lesson_7/G1_G2.png" class="img-fluid figure-img"></p>
<figcaption class="figure-caption">Figure&nbsp;3: Plot of G1 and G2</figcaption>
</figure>
</div>
<p>單純看這個圖，我們就知道如果 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 要最大化 Lagrangian，那就是極化的，在兩端 <img src="https://latex.codecogs.com/png.latex?G(x)"> 是正的部分全 1，中間負的部分全 0。</p>
<p>但真的是這樣嗎?</p>
<p>因為 <img src="https://latex.codecogs.com/png.latex?G_1(x),%20G_2(x)"> 在開頭和結尾的斜率都一致，所以會不會 <strong>剛好重和</strong>。那樣一來 <img src="https://latex.codecogs.com/png.latex?G(x)"> 就是零，所以 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 可以是任意值。無差異! Indifference!</p>
<p>但也不一定要取到剛好一樣，如果可以的話，只要讓 <img src="https://latex.codecogs.com/png.latex?G(x)"> 一定小於等於 0 就行了。Player B 有辦法辦到嗎? 我們解端點 0 和 1 時的不等式(這邊的 <img src="https://latex.codecogs.com/png.latex?G_2(x)"> 我使用沒有帶面積條件的版本 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:Gx-pieces%7D">): <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bcases%7D%0A(P+B)y_1%5E*%20-%20B%20%5Cleq%200%20%5C%5C%0A(P+2B)%20-%20B(1+y_1%5E*)%20%5Cleq%20%5CBig(%20(P+2B)%20-%20B(1%20-%20z_1%5E*%20+%20z_2%5E*)%20%5CBig)%20%5C%5C%0A%5Cend%7Bcases%7D%0A"> 也就是 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bcases%7D%0A%5Cdisplaystyle%20y_1%5E*%20%5Cleq%20%5Cfrac%7BB%7D%7BP+B%7D%20%5C%5C%0A%5Cdisplaystyle%20z_2%5E*%20-%20z_1%5E*%20%5Cleq%20y_1%5E*%20%5C%5C%0A%5Cend%7Bcases%7D%20%5Ctag%7B13%7D%5Clabel%7Beq:inequalities-from-endpoints%7D%0A"> 假設可以取到，那麼 <img src="https://latex.codecogs.com/png.latex?G(x)%20%5Cleq%200"> 對所有 <img src="https://latex.codecogs.com/png.latex?x%20%5Cin%20%5B0,1%5D"> 都成立，這樣 Lagrangian 最大值就是 <img src="https://latex.codecogs.com/png.latex?J(x,y)"> 的積分值 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:Jxy-integral-with-constraints%7D">。還是帶有 <img src="https://latex.codecogs.com/png.latex?z_1%5E*,%20z_2%5E*">，所以我們要把它具體解出來。</p>
<p>BTW, 如果 <img src="https://latex.codecogs.com/png.latex?G"> 讓出一點點正的部分給 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 可以因此壓低的 <img src="https://latex.codecogs.com/png.latex?J"> 的積分值的話，那我這樣就解錯了，但我們猜應該不會，這是這類 Indifference principle 不嚴謹的地方。而且根據該原則，其實上面兩個等號一定會成立，因為那是<strong>最</strong>讓 Player A 感受到無差異的條件: 所有 <img src="https://latex.codecogs.com/png.latex?G(x)=0"> 的地方 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 的取值都不影響結果。如果嚴格小於，那 Player A 在那裡的 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 一定會取 0。而直覺上 Player B 會在另個其他某個地方付出代價。這部分也不嚴謹。</p>
<p>還是來算算看，根據面積條件 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z1z2-equations%7D">，假設 <img src="https://latex.codecogs.com/png.latex?z_1%5E*%20=%20Bt">，那麼 <img src="https://latex.codecogs.com/png.latex?z_2%5E*%20=%201%20-%20(P+B)t">，所以 <img src="https://latex.codecogs.com/png.latex?z_2%5E*%20-%20z_1%5E*%20=%201%20-%20(P+2B)t">，而他最多是 <img src="https://latex.codecogs.com/png.latex?B/(P+B)">，所以 <img src="https://latex.codecogs.com/png.latex?%0At%20%5Cgeq%20%5Cfrac%7BP%7D%7B(P+B)(P+2B)%7D%0A"></p>
<p>另一方面 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmathcal%7BL%7D_%7Bmax%7D%0A&amp;=%20%5Cfrac%7BP%7D%7B2%7D(1%20-%20z_1%5E*)%5E2%20+%20B(1%20-%20z_2%5E*)%5E2%20%5C%5C%0A&amp;=%20%5Cfrac%7BP%7D%7B2%7D(1%20-%20Bt)%5E2%20+%20B%5CBig((P+B)t%5CBig)%5E2%20%20%5C%5C%0A&amp;=%20%5Cfrac%7BP%7D%7B2%7D%20-%20PBt%20+%20%5CBig(%20B(P+B)%5E2%20+%20%5Cfrac%7BPB%5E2%7D%7B2%7D%20%5CBig)%20t%5E2%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 是個開口向上的二次函數，因為 <img src="https://latex.codecogs.com/png.latex?t"> 是 Player B 控制的，要選 <img src="https://latex.codecogs.com/png.latex?t"> 讓它最小化。而其對稱軸位於 <img src="https://latex.codecogs.com/png.latex?%0At_%7B%5Cmin%7D%20=%20%5Cfrac%7BPB%7D%7B2%5CBig(%20B(P+B)%5E2%20+%20%5Cfrac%7BPB%5E2%7D%7B2%7D%20%5CBig)%7D%20=%20%5Cfrac%7BP%7D%7B(2P+B)(P+2B)%7D%20%3C%20%5Cfrac%7BP%7D%7B(P+B)(P+2B)%7D%20%5Cleq%20t%0A"> 所以最佳的 <img src="https://latex.codecogs.com/png.latex?t"> 果然是取到等號成立: <img src="https://latex.codecogs.com/png.latex?%0At%5E*%20=%20%5Cfrac%7BP%7D%7B(P+B)(P+2B)%7D%20%20%0A"> 所以 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;z_1%5E*%20=%20%5Cfrac%7BBP%7D%7B(P+B)(P+2B)%7D%20,%20%5Cquad%20z_2%5E*%20=%20%5Cfrac%7B2B%7D%7BP+2B%7D%20%5C%5C%0A&amp;y_1%5E*%20=%20%5Cfrac%7BB%7D%7BP+B%7D%20%5C%5C%0A%5Cend%7Balign%7D%20%20%5Ctag%7B14%7D%5Clabel%7Beq:final-z1z2y1%7D%0A"></p>
<p>以上推導應該還要再驗證，若不等式 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:inequalities-from-endpoints%7D"> 不成立，<img src="https://latex.codecogs.com/png.latex?a_1(x)%5Ccdot%20G(x)"> 所增加的量，會比 <img src="https://latex.codecogs.com/png.latex?J(x,y)"> 所減少的量還多。這樣才保證 Player B 成功使 Lagrangian 最小化。但其實不太可能，因為如此一來，Player A 就不是針對 Player B 打出最佳攻擊了。但在 Nash Equilibrium 時，雙方都是最佳防守狀態，也都是彼此的最佳攻擊。所以在 Nash Equilibrium 狀態下，以上推導是成立的。</p>
<p>而 Player B 取這個 <img src="https://latex.codecogs.com/png.latex?t%5E*"> 時，Lagrangian 是多少呢? 因為上面 <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D_%7Bmax%7D"> 的式子中，<img src="https://latex.codecogs.com/png.latex?t=0"> 時會是 <img src="https://latex.codecogs.com/png.latex?P/2"> 也就是池底的一半，所以在 <img src="https://latex.codecogs.com/png.latex?%5B0,%202t_%7B%5Cmin%7D%5D"> 之間 <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D_%7Bmax%7D"> 會小於 <img src="https://latex.codecogs.com/png.latex?P/2">，超過 <img src="https://latex.codecogs.com/png.latex?2t_%7B%5Cmin%7D"> 後就會大於 <img src="https://latex.codecogs.com/png.latex?P/2">。而我們的 <img src="https://latex.codecogs.com/png.latex?t%5E*"> 是小於 <img src="https://latex.codecogs.com/png.latex?2t_%7B%5Cmin%7D"> 的! <img src="https://latex.codecogs.com/png.latex?%0At%5E*%20=%20%5Cfrac%7BP%7D%7B(P+B)(P+2B)%7D%20%3C%202t_%7B%5Cmin%7D%20=%20%5Cfrac%7B2P%7D%7B(2P+B)(P+2B)%7D%0A"> 所以 Player A 的整體期望值是小於池底一半的! 也就是<strong>先手劣勢</strong>。</p>
<p>如此一來 Game Value 有了，具體來說是: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cmax_%7Ba_1,%20a_2%7D%20%5Cmin_%7Bb_1,%20b_2%7D%20%5Cmathcal%7BL%7D(a_1,%20a_2,%20b_1,%20b_2)%20%20%20%20%5C%5C%0A&amp;%5Cquad%20=%20%5Cfrac%7BP%7D%7B2%7D%20-%20t%5E*%20B%20%5Cleft(P%20-%20%5Cfrac%7B(2P+B)(P+2B)%7D%7B2%7D%20t%5E*%20%5Cright)%20%20%20%20%5C%5C%0A&amp;%5Cquad%20=%20%5Cfrac%7BP%7D%7B2%7D%20-%20%5Cfrac%7BP%7D%7B(P+B)(P+2B)%7D%5Ccdot%20B%20%5Cleft(%20P%20-%20%5Cfrac%7BP(2P+B)%7D%7B2(P+B)%7D%20%5Cright)%20%5C%5C%0A&amp;%5Cquad%20=%20%5Cfrac%7BP%7D%7B2%7D%20-%20%5Cfrac%7BP%5E2B%5E2%7D%7B2(P+2B)(P+B)%5E2%7D%20%20%5Ctag%7B15%7D%5Clabel%7Beq:game-value-final%7D%0A%5Cend%7Balign%7D%0A"> 總結以上的解法，Player B 打出最佳防守 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:final-z1z2y1%7D"> 時，是不需要知道 Player A 的策略的，所以這並非 Player B 的最佳攻擊策略。Player A 此時被無差異化了，所以 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 在 <img src="https://latex.codecogs.com/png.latex?%5Bz_1%5E*,%20z_2%5E*%5D"> 是 <img src="https://latex.codecogs.com/png.latex?0">，其他地方可以任意。</p>
<p>但若 Player B 可以根據 Player A 的策略來動態調整，那麼 Player B 的 <img src="https://latex.codecogs.com/png.latex?y_1%5E*,%20z_1%5E*,%20z_2%5E*"> 就會依照 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z1z2-equations%7D"> 的面積比例去切分。此時 Player A 要如何選擇 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 才能最大化 Lagrangian?</p>
<p>如果繼續沿用剛才的邏輯，當 Nash Equilibrium 時，Player B 的最佳防守策略 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:final-z1z2y1%7D"> 會是對 Player A 的最佳攻擊，所以其實 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:final-z1z2y1%7D"> 也剛好會把 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 依照 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:z1z2-equations%7D"> 的比例去切分。</p>
<p>所以說，<img src="https://latex.codecogs.com/png.latex?(1-a_1(x))"> 在 <img src="https://latex.codecogs.com/png.latex?%5Bz_1%5E*,%20z_2%5E*%5D"> 部分的面積，比上 <img src="https://latex.codecogs.com/png.latex?%5Bz_2%5E*,%201%5D"> 部分的面積，會是 <img src="https://latex.codecogs.com/png.latex?(B%20+%20%5Cfrac%7BP%7D%7B2%7D)%20:%20%5Cfrac%7BP%7D%7B2%7D"> 的比例。而因為 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 在 <img src="https://latex.codecogs.com/png.latex?%5Bz_1%5E*,%20z_2%5E*%5D"> 是 <img src="https://latex.codecogs.com/png.latex?0">，所以 <img src="https://latex.codecogs.com/png.latex?(1-a_1(x))"> 在這區間的面積就是 <img src="https://latex.codecogs.com/png.latex?z_2%5E*%20-%20z_1%5E*">。所以剩下要算的就是 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 在 <img src="https://latex.codecogs.com/png.latex?%5Bz_2%5E*,%201%5D"> 的部分是多少。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B1%20-%20z_2%5E*%20-%20A_%7Bvalue%7D%7D%7Bz_2%5E*%20-%20z_1%5E*%7D%20=%20%5Cfrac%7BP%7D%7B2B%20+%20P%7D%0A"> 帶 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:final-z1z2y1%7D"> 解出 <img src="https://latex.codecogs.com/png.latex?%0AA_%7Bvalue%7D%20=%20%5Cfrac%7BP%7D%7BP%20+%202B%7D%5Cfrac%7BP%7D%7BP+B%7D%0A"> 而 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 在 <img src="https://latex.codecogs.com/png.latex?%5B0,%20z_1%5E*%5D"> 的部分面積需要是 <img src="https://latex.codecogs.com/png.latex?A"> 的 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7BB%7D%7BP+B%7D">， 所以 <img src="https://latex.codecogs.com/png.latex?%0AA_%7Bbluff%7D%20=%20%5Cfrac%7BB%7D%7BP+B%7D%20A_%7Bvalue%7D%20=%20%5Cfrac%7BP%5E2B%7D%7B(P+2B)(P+B)%5E2%7D%0A"></p>
<div id="fig-final-a1-optimal-strategy" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/poker/images/lesson_7/a1_optimal.png" class="img-fluid figure-img"></p>
<figcaption class="figure-caption">Figure&nbsp;4: Final <img src="https://latex.codecogs.com/png.latex?a_1(x)"> Optimal Strategy</figcaption>
</figure>
</div>
<p>現在算出了 <img src="https://latex.codecogs.com/png.latex?a_1(x)"> 在兩邊的面積是多少，那形狀呢? 剛才的 Lagrangian 似乎就被面積決定了，也沒有提到形狀的問題。沒錯，Lagrangian 只跟面積有關，所以形狀可以任意。</p>
<!-- 

### 走錯路 (可跳過) 

現在帶回 Lagrangian，這邊回憶一下，從推導過程可以發現 其實 $G_2(x) = \int_0^1 J(x,y) dy$ ，所以我們把常數項合併回去給 $G_2$:
$$
\begin{align}
\mathcal{L}(a_1) &= \int_0^1 \int_0^1 J(x,y) \, dy \, dx + \int_0^1 a_1(x) \cdot G(x) \, dx \\
&= \int_0^1 a_1(x) \cdot G_1(x) \, dx + \int_0^1 (1 - a_1(x)) \cdot G_2(x) \, dx \\
\end{align}
$$
我們又回到了簡潔的式子，第一項就是 Player A bet 的情況，第二項是 Player A check 的情況。

交換一下順序，假設 $y_1^*$ 固定，$z_2^* = 1 - \frac{P+B}{B}z_1^*$。待會再回來解 $y_1^*, z_1^*$。

根據 \eqref{eq:z1z2-equations}，在這兩個條件下，我們來看 $a_1(x)$ 要怎麼取可以最大化 Lagrangian。

$$
\begin{align}
\mathcal{L}(a_1) 
&=  \int_0^{y_1^*} a_1(x)\cdot \Big((P+B)y_1^* - B\Big) \, dx + \int_{y_1^*}^1 a_1(x) \cdot \Big( (P+2B)x - B(1+y_1^*) \Big) dx \\
&\quad + \int_{z_1^*}^{z_2^*} (1 - a_1(x)) \cdot P(x - z_1^*) \, dx \\
&\quad + \int_{z_2^*}^1 (1 - a_1(x)) \cdot \Big( (P+2B)(x+z_1^*) - 2B \Big) dx \\
\end{align}
$$
神奇的是，Part 1 的 $y_1^*$ 自己消掉了，而 Part 2 的 $z_1^*$ 也自己消掉了。

\begin{align}
\mathcal{L}(a_1) 
&=  y_1^* \cdot \underbrace{\left(
  \int_0^{y_1^*} a_1(x)\cdot(P+B) \, dx - \int_{y_1^*}^1 a_1(x) \cdot B dx \\
  \right)}_{=0} \\
&\qquad + (P+2B) \cdot \int_{y_1^*}^1 a_1(x) \cdot x \, dx - B \int_{0}^1 a_1(x) \, dx \\
&\qquad + z_1^* \cdot \underbrace{\left( 
  \int_{z_1^*}^{z_2^*} (1 - a_1(x)) \cdot (-P) \, dx + \int_{z_2^*}^1 (1 - a_1(x)) \cdot (P+2B) \, dx 
  \right)}_{=0} \\
&\qquad + (2P+2B) \cdot \int_{z_1^*}^1 (1 - a_1(x)) \cdot x \, dx - 2B \int_{z_2^*}^1 (1 - a_1(x)) \, dx \\

&= (P+2B) \cdot \int_{y_1^*}^1 a_1(x) \cdot x \, dx - B \int_{0}^1 a_1(x) \, dx \\
&\qquad + P \cdot \int_{z_1^*}^{z_2^*} (1 - a_1(x)) \cdot x \, dx + (P+2B) \cdot \int_{z_2^*}^1 (1 - a_1(x)) \cdot x \, dx - 2B \int_{z_2^*}^1 (1 - a_1(x)) \, dx  \\

&= \underbrace{(P+2B) \cdot \int_{y_1^*}^{z_2^*} a_1(x) \cdot x \, dx - P \cdot \int_{z_1^*}^{z_2^*} a_1(x) \cdot x \, dx}_{a_1(x)\cdot x \text{ related}} \\
&\qquad - B \int_0^1 a_1(x) \, dx + P\int_{z_1^*}^{z_2^*} x \, dx + (P+2B) \int_{z_2^*}^1 x \, dx - 2B \int_{z_2^*}^1 (1-a_1(x)) dx  \\
\end{align}


一番整理後還算是乾淨。直覺上 $y_1^*$ 應該在 $z_1^*$ 和 $z_2^*$ 之間，但我們來確認一下。

這裡變數有點多，先這樣想，這些 $y_1^*, z_1^*, z_2^*$ 都是限制 $a_1(x)$ 或者 $1-a_1(x)$ 面積積分的條件，所以當我們把 $[0,1]$ 區間切成四個部分，如下圖所示 ，我們假設 $A_1, A_2, A_3, A_4$ 是固定的，且滿足面積的條件，那麼這固定的面積無論在這範圍內怎麼動，都依然滿足面積的限制。 

![$a_1(x)$ Area Division. Schematic Diagram](images/lesson_7/a1_area.png){#fig-a1-area}

### 以下部分開始算錯 ... 

在面積可以在自己的那一格區域亂流動的情況下， $a_1(x)\cdot x$ 這一項就會有影響了，而 Player A 要選如何最大化 Lagrangian。來看看含有這的兩項
$$
(P+2B) \cdot \int_{y_1^*}^1 a_1(x) \cdot x \, dx - 2(P+B) \cdot \int_{z_1^*}^1 a_1(x) \cdot x \, dx
$$

* Case 1: 如果 $z_1^* < y_1^*$ 的話，負的項可以把正的項完全吃掉:
  $$
  -(P+2B) \cdot \int_{z_1^*}^{y_1^*} a_1(x) \cdot x \, dx - P \cdot \int_{z_1^*}^1 a_1(x) \cdot x \, dx, \qquad \text{, if } z_1^* < y_1^*
  $$
  因為 $a_1(x)$ 要最大化 Lagrangian，所以在區域 $[z_1^*, 1]$ 之間的面積，都要在該區域內盡量往左邊靠，而在區域 $[0, z_1^*]$ 之間則是任意，跟 Lagrangian 無關。

* Case 2: 若是 $y_1^* \leq z_1^*$ 的話，就有正有負:
  $$
  (P+2B) \cdot \int_{y_1^*}^{z_1^*} a_1(x) \cdot x \, dx - P \cdot \int_{z_1^*}^1 a_1(x) \cdot x \, dx, \qquad \text{, if } y_1^* \leq z_1^*
  $$
  類似地，在區域 $[y_1^*, 1]$ 之間的面積要往右邊靠，在區域 $[z_1^*, 1]$ 之間的面積要往左邊靠，而在區域 $[0, y_1^*]$ 之間任意。

![$a_1(x)$ Area Tendency. Schematic Diagram](images/lesson_7/two_cases_lean_tendency.png){#fig-a1-lean-tendency}

**先假設是 Case 1:**

那麼我們目前有的條件是:
$$
\begin{align}
\int_0^{z_1^*} a_1(x) dx = A_1 &\qquad\text{, } \int_0^{z_1^*} (1-a_1(x)) dx = C_1  \\
\int_{z_1^*}^{y_1^*} a_1(x) dx = A_2 &\qquad\text{, } \int_{z_1^*}^{y_1^*} (1-a_1(x)) dx = C_2  \\
\int_{y_1^*}^{z_2^*} a_1(x) dx = A_3 &\qquad\text{, } \int_{y_1^*}^{z_2^*} (1-a_1(x)) dx = C_3  \\
\int_{z_2^*}^1 a_1(x) dx = A_4 &\qquad\text{, } \int_{z_2^*}^1 (1-a_1(x)) dx = C_4  \\
\frac{A_1 + A_2}{A_3 + A_4} &= \frac{B}{P+B}  \tag{4'}\label{eq:area-ratio-a} \\
\frac{C_2 + C_3}{C_4} &= \frac{2B + P}{P}   \tag{8-1}\label{eq:area-ratio-c} \\
\frac{A_1 + C_1}{A_4+C_4} &= \frac{B}{P+B}   \tag{8-2}\label{eq:area-ratio-ac} \\
\sum_{i=1}^4 A_i + C_i &= 1  \tag{Area Total}
\end{align}
$$

這邊的重點是他們變成了齊次的形式，總和是 $1$。



我們來看 Lagrangian，因為是 Case 1，所以:
$$
\begin{aligned}
\mathcal{L}(a_1) 
&= - (P+2B)  \int_{z_1^*}^{y_1^*} a_1(x)\cdot x \, dx - P \int_{z_1^*}^{1} a_1(x)\cdot x \, dx  \\
&\qquad -B \int_0^1 a_1(x) \, dx + 2(P+B) \cdot \frac{1-(z_1^*)^2}{2} -2B \cdot \int_{z_2^*}^1 (1-a_1(x)) \, dx  \\
\end{aligned}
$$
根據剛才的傾向分析，我們可以算出 $a_1(x)\cdot x$ 的積分項，比方說因為 $a_1(x)$ 在區域 $[z_1^*, y_1^*]$ 是 $\mathbb{1}_{z_1^*\leq x\leq z_1^*+A_2}$ 等等。

所以我們把積分算出來，然後盡量用 $A_i, C_i$ 來表示:
$$
\begin{aligned}
\mathcal{L}(a_1) 
&= - (P+2B) \frac{(z_1^*+A_2)^2 - (z_1^*)^2}{2}  \\
&\qquad - P \frac{(z_1^*+A_2)^2 - (z_1^*)^2 + (y_1^*+A_3)^2 - (y_1^*)^2 + (z_2^*+A_4)^2 - (z_2^*)^2 }{2}  \\
&\qquad - B (A_1 + A_2 + A_3 + A_4) + 2(P+B) \cdot \frac{1-(z_1^*)^2}{2} -2B\cdot C_4 \\
\end{aligned}
$$
若將 $P, B$ 視為常數，$A_i, C_i$ 視為變數，我們可以看出有一次式和二次式的部分。但因為有總合為1的條件，所以其實一次或二次並非那麼 well-defined。

利用
$$
\begin{aligned}
&z_1^* = A_1 + C_1, \\
&y_1^* = A_1 + A_2 + C_1 + C_2, \\
&z_2^* = A_1 + A_2 + A_3 + C_1 + C_2 + C_3, \\
\end{aligned}
$$
將這些變數代換掉，

$$
\begin{aligned}
\mathcal{L}(a_1) 
&= - (2P+2B) \frac{(z_1^*+A_2)^2 - (z_1^*)^2}{2} + 2(P+B) \cdot \frac{1-(z_1^*)^2}{2}   \\
&\qquad - P \frac{(y_1^*+A_3)^2 - (y_1^*)^2 + (z_2^*+A_4)^2 - (z_2^*)^2 }{2}  \\
&\qquad - B (A_1 + A_2 + A_3 + A_4 + 2C_4)  \\
&= (P+B)\cdot (1 - (A_1 + C_1 + A_2)^2) \\
&\qquad - P \cdot \left(A_3 \Big(A_1+A_2+C_1+C_2+\frac{A_3}{2}\Big) + A_4 \Big(A_1+A_2+A_3+C_1+C_2+C_3+\frac{A_4}{2}\Big) \right)  \\
&\qquad - B (A_1 + A_2 + A_3 + A_4 + 2C_4)  \\
\end{aligned}
$$
我們來試著在限制條件 \eqref{eq:area-ratio-a}, \eqref{eq:area-ratio-c}, \eqref{eq:area-ratio-ac} 下進行變分，發現當做以下的微小變動時，限制仍然滿足
$$
\begin{aligned}
(A_1, A_2, A_3, A_4, C_1, C_2, C_3, C_4) &\rightarrow (A_1, A_2, A_3, A_4, C_1, C_2-\varepsilon, C_3+\varepsilon, C_4) \\
\mathcal{L} &\rightarrow \mathcal{L} + P \cdot A_3 \cdot \varepsilon \\
\end{aligned}
$$
所以若 $A_3 > 0$，$C_2$ 必須為 $0$ 才能最大化 Lagrangian。或者說 $A_3 = 0$。無論如何，我們得到
$$
A_3 C_2 = 0  
$$

使用變數代換 $A_1+A_2+C_1=\alpha$，以及 $A_3 + A_4 = \beta$: 
$$
\begin{aligned}
\mathcal{L}(a_1) 
&= (P+B)\cdot (1 - \alpha^2) \\
&\qquad - P \cdot \left( \cancelto{0}{A_3 C_2} + A_3 \alpha +\frac{(A_3+A_4)^2}{2} + A_4 (\alpha+C_4\cdot\frac{2B+P}{P}) \right)  \\
&\qquad - B (A_1 + A_2 + A_3 + A_4 + 2C_4)  \\
&= (P+B)\cdot (1 - \alpha^2) \\
&\qquad - P \cdot \left( A_4 C_4\cdot\frac{2B+P}{P} + (A_3+A_4) \alpha +\frac{(A_3+A_4)^2}{2} \right)  \\
&\qquad - B ((A_3 + A_4)\cdot\frac{P+2B}{P+B} + 2C_4)  \\
&= (P+B)\cdot (1 - \alpha^2) \\
&\qquad - P \cdot \left(A_4 C_4\cdot\frac{2B+P}{P} + \beta\alpha +\frac{\beta^2}{2} \right)  \\
&\qquad - B (\beta \cdot\frac{P+2B}{P+B} + 2C_4)  \\
\end{aligned}
$$

接對 $A_i$ 的部分做一個高端變分操作，同樣保持面積比例的等式，而且 $\alpha$ 和 $\beta$ 在這變換下也不變:
$$
\begin{aligned}
(A_1, A_2, A_3, A_4)
&\rightarrow (A_1-(P+B)\varepsilon, A_2+(P+B)\varepsilon, A_3+B\varepsilon, A_4-B\varepsilon) \\
\mathcal{L} &\rightarrow \mathcal{L} + C_4 \cdot (P+2B) \cdot \varepsilon \\
\end{aligned}
$$
因此，若 $C_4 > 0$，則 $A_1$ 或 $A_4$ 必須為 $0$ 否則就有空間讓 Lagrangian 變大。
也就是說，
$$
A_1 A_4 C_4 = 0  
$$
由總面積為 1 的條件，
$$
1 = \alpha + \beta + C_4 + C_4\cdot\frac{P+2B}{P}
$$
將 $C_4 = \frac{P}{2(P+B)}(1 - \alpha - \beta)$ 帶回 Lagrangian:
$$
\begin{aligned}
\mathcal{L}(a_1) 
&= -(P+B) \alpha^2 + (P+B) \\
&\qquad - \frac{P}{2}\beta^2 - P\alpha\beta - A_4 (2B+P) \cdot \frac{P}{2(P+B)}(1 - \alpha - \beta) \\
&\qquad - \frac{B(P+2B)}{P+B} \beta - B \cdot \frac{P}{P+B}(1 - \alpha - \beta)  \\
&= -(P+B) \alpha^2 - \frac{P}{2}\beta^2 - P\alpha\beta \\
&\qquad - \left( \frac{A_4\cdot (PB+\frac{P^2}{2}) + PB }{P+B}  \right) (1 - \alpha - \beta) - \frac{B(P+2B)}{P+B} \beta + (P+B)  \\
\end{aligned}
$$

這邊的 $A_4$ 可以視為自由變數，因為我們現在的所有 8 個變數變成 三個變數: $\alpha, \beta, A_4$，為此，我們應該將其他所有都用這三個變數表示出來。
$$
\begin{aligned}
C_4 &= \frac{P}{2(P+B)}(1 - \alpha - \beta) \\
C_1 &= \alpha - \frac{B}{P+B}\beta \\
A_3 &= \beta - A_4 \\
A_1 &= \frac{B}{P+B}(A_4+C_4) - C_1 = \frac{B}{P+B} \left( A_4 + \frac{P}{2(P+B)}(1 - \alpha - \beta) \right) - \left( \alpha - \frac{B}{P+B}\beta \right) \\
A_2 &= \frac{B}{P+B}\beta - A_1 = \frac{B}{P+B}\beta - \left[ \frac{B}{P+B} \left( A_4 + \frac{P}{2(P+B)}(1 - \alpha - \beta) \right) - \left( \alpha - \frac{B}{P+B}\beta \right) \right] \\
&\qquad\qquad\qquad\qquad = \alpha - \frac{B}{P+B} A_4 - \frac{BP}{2(P+B)^2}(1 - \alpha - \beta) \\
C_2 + C_3 &= C_4 \cdot \frac{2B + P}{P} = \frac{(2B + P)}{2(P+B)}(1 - \alpha - \beta) \\
A_3C_2 &= 0 \\
\end{aligned}
$$
確實可以表示出來，但需要在 0 和 1 之間，變成爆出了一大堆不等式限制。


 -->


</section>

 ]]></description>
  <category>Poker</category>
  <guid>https://your-website-url.example.com/posts/poker/lesson_7_comparison_full.html</guid>
  <pubDate>Mon, 22 Dec 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>Poker Lesson 6 - 極化的範圍 (Polarized Range) - 比大小遊戲</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/poker/lesson_6_comparison.html</link>
  <description><![CDATA[ 




<p>在上一篇文章中，我們探討了<strong>單向資訊不對稱</strong>（Player A 全盲、Player B 全知）的極端狀況，並推導出了最佳詐唬與跟注頻率。我們利用了「雙曲面」與「翹翹板」的心智模型，解釋了雙方如何在這個資訊落差中尋找平衡。</p>
<p>然而，現實的德州撲克遠比那個模型複雜。為了更接近真實，我們需要引入另一個維度的簡化模型——<strong>「比大小遊戲」（High Card Game）</strong>。</p>
<section id="遊戲規則" class="level3">
<h3 class="anchored" data-anchor-id="遊戲規則">遊戲規則</h3>
<p>讓我們設定一個標準的賽局環境：</p>
<ul>
<li><strong>玩家</strong>：Player A 與 Player B。</li>
<li><strong>底池 (Pot)</strong>：<img src="https://latex.codecogs.com/png.latex?P"> 元（可視為雙方起始強迫下注 <img src="https://latex.codecogs.com/png.latex?P/2">）。</li>
<li><strong>發牌</strong>：從一副撲克牌中，雙方各發一張牌，彼此皆看不到對方的牌（資訊對稱且隱蔽）。</li>
<li><strong>攤牌時勝負判定</strong>：
<ul>
<li>數字較大者獲勝，贏走底池。</li>
<li>若數字相同則平手，雙方拿回各自的下注。</li>
</ul></li>
<li><strong>下注流程</strong>：
<ul>
<li>設定每次下注金額為 <img src="https://latex.codecogs.com/png.latex?B"> 元。</li>
<li>Player A（先手）：可以選擇 <strong>下注 (Bet)</strong> 或 <strong>過牌 (Check)</strong>。</li>
<li>若 Player A 選擇 <strong>過牌 (Check)</strong>，則輪到 Player B 行動，B 同樣可以選擇 <strong>下注</strong> 或 <strong>過牌</strong>。</li>
<li>若 Player A 選擇 <strong>下注 (Bet)</strong>，則輪到 Player B 行動，B 可以選擇 <strong>跟注 (Call)</strong> 或 <strong>棄牌 (Fold)</strong>。</li>
</ul></li>
</ul>
<p>一般是這樣的。</p>
<p>不過這對現在的我們來說還是太複雜了，所以我們再做更進一步的簡化：</p>
<blockquote class="blockquote">
<p><span style="color: red;">假設 若 Player A 選擇 <strong>過牌 (Check)</strong>，則 Player B 也必須 <strong>過牌 (Check)</strong>。</span></p>
</blockquote>
<p>也就是說只有 Player A 可以進攻，Player B 只能被動回應。</p>
<p>這樣一來，遊戲流程就變成：</p>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div id="fig-game-tree-highlighted" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-game-tree-highlighted-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<svg width="672" height="480" viewbox="0.00 0.00 501.85 217.40" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" style="; max-width: none; max-height: none">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 213.4)">
<title>GT_Highlight_Bigger</title>
<polygon fill="white" stroke="transparent" points="-4,4 -4,-213.4 497.85,-213.4 497.85,4 -4,4"></polygon>
<!-- A -->
<g id="node1" class="node">
<title>A</title>
<ellipse fill="white" stroke="#1565c0" stroke-width="2" cx="54.71" cy="-57" rx="54.93" ry="54.93"></ellipse>
<text text-anchor="middle" x="54.71" y="-52.8" font-family="Helvetica, Arial, sans-serif" font-size="14.00">Player A</text>
</g>
<!-- B -->
<g id="node2" class="node">
<title>B</title>
<ellipse fill="white" stroke="#1565c0" stroke-width="2" cx="263.1" cy="-150" rx="54.33" ry="54.33"></ellipse>
<text text-anchor="middle" x="263.1" y="-145.8" font-family="Helvetica, Arial, sans-serif" font-size="14.00">Player B</text>
</g>
<!-- A&#45;&gt;B -->
<g id="edge1" class="edge">
<title>A-&gt;B</title>
<path fill="none" stroke="black" d="M104.89,-79.16C134.6,-92.55 172.64,-109.69 203.85,-123.75"></path>
<polygon fill="black" stroke="black" points="202.75,-127.09 213.31,-128.01 205.63,-120.71 202.75,-127.09"></polygon>
<text text-anchor="middle" x="157.52" y="-117.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 下注 (Bet) </text>
</g>
<!-- Outcome_Check -->
<g id="node3" class="node">
<title>Outcome_Check</title>
<polygon fill="#ffebee" stroke="transparent" points="219.6,-14 219.6,-64 306.6,-64 306.6,-14 219.6,-14"></polygon>
<text text-anchor="start" x="226.61" y="-46.2" font-family="Helvetica, Arial, sans-serif" font-size="12.00">結局 1 (強制攤牌)</text>
<text text-anchor="start" x="250.68" y="-24" font-family="Helvetica, Arial, sans-serif" font-size="10.00">池底: P</text>
<polygon fill="none" stroke="red" stroke-width="2" points="220.6,-15 220.6,-63 305.6,-63 305.6,-15 220.6,-15"></polygon>
</g>
<!-- A&#45;&gt;Outcome_Check -->
<g id="edge2" class="edge">
<title>A-&gt;Outcome_Check</title>
<path fill="none" stroke="red" stroke-width="2" stroke-dasharray="5,2" d="M109.4,-52.32C135.68,-50.03 167.56,-47.25 195.39,-44.82"></path>
<polygon fill="red" stroke="red" stroke-width="2" points="195.78,-48.3 205.44,-43.94 195.17,-41.32 195.78,-48.3"></polygon>
<text text-anchor="middle" x="157.52" y="-54.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00" fill="red"> 過牌 (Check) </text>
</g>
<!-- Outcome_Call -->
<g id="node4" class="node">
<title>Outcome_Call</title>
<path fill="#f5f5f5" stroke="black" d="M480.13,-209.3C480.13,-209.3 422.58,-209.3 422.58,-209.3 416.58,-209.3 410.58,-203.3 410.58,-197.3 410.58,-197.3 410.58,-170.7 410.58,-170.7 410.58,-164.7 416.58,-158.7 422.58,-158.7 422.58,-158.7 480.13,-158.7 480.13,-158.7 486.13,-158.7 492.13,-164.7 492.13,-170.7 492.13,-170.7 492.13,-197.3 492.13,-197.3 492.13,-203.3 486.13,-209.3 480.13,-209.3"></path>
<text text-anchor="middle" x="451.35" y="-187.6" font-family="Helvetica, Arial, sans-serif" font-size="12.00">結局 2: 攤牌</text>
<text text-anchor="middle" x="451.35" y="-173.2" font-family="Helvetica, Arial, sans-serif" font-size="12.00">(池底: P+2B)</text>
</g>
<!-- B&#45;&gt;Outcome_Call -->
<g id="edge3" class="edge">
<title>B-&gt;Outcome_Call</title>
<path fill="none" stroke="black" d="M316.48,-159.56C342.79,-164.36 374.51,-170.15 400.46,-174.89"></path>
<polygon fill="black" stroke="black" points="400,-178.37 410.47,-176.72 401.26,-171.48 400,-178.37"></polygon>
<text text-anchor="middle" x="364.73" y="-176.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 跟注 (Call) </text>
</g>
<!-- Outcome_Fold -->
<g id="node5" class="node">
<title>Outcome_Fold</title>
<path fill="#f5f5f5" stroke="black" d="M481.85,-140.3C481.85,-140.3 420.85,-140.3 420.85,-140.3 414.85,-140.3 408.85,-134.3 408.85,-128.3 408.85,-128.3 408.85,-101.7 408.85,-101.7 408.85,-95.7 414.85,-89.7 420.85,-89.7 420.85,-89.7 481.85,-89.7 481.85,-89.7 487.85,-89.7 493.85,-95.7 493.85,-101.7 493.85,-101.7 493.85,-128.3 493.85,-128.3 493.85,-134.3 487.85,-140.3 481.85,-140.3"></path>
<text text-anchor="middle" x="451.35" y="-118.6" font-family="Helvetica, Arial, sans-serif" font-size="12.00">結局 3: A 獲勝</text>
<text text-anchor="middle" x="451.35" y="-104.2" font-family="Helvetica, Arial, sans-serif" font-size="12.00">(B 放棄)</text>
</g>
<!-- B&#45;&gt;Outcome_Fold -->
<g id="edge4" class="edge">
<title>B-&gt;Outcome_Fold</title>
<path fill="none" stroke="black" d="M316.48,-140.16C342.22,-135.32 373.14,-129.51 398.77,-124.69"></path>
<polygon fill="black" stroke="black" points="399.49,-128.12 408.67,-122.83 398.2,-121.24 399.49,-128.12"></polygon>
<text text-anchor="middle" x="364.73" y="-138.3" font-family="Helvetica, Arial, sans-serif" font-size="11.00"> 棄牌 (Fold) </text>
</g>
</g>
</svg>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-game-tree-highlighted-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Simplified Game Tree for High Card Game
</figcaption>
</figure>
</div>
</div>
</div>
<p>看起來 Player A 應該有巨大的優勢，不只是先手，而且 Player B 還不能主動進攻。</p>
<p>我們今天就要來算算，Player A 究竟能拿到多少優勢，以及 Player B 又該如何防守呢？</p>
<p>這是雙方資訊完全對稱 (全盲)，單純在討論這種 bet-call-check 的遊戲規則機制下，甚麼是最佳策略的分析。</p>
<p>今天用的方法不算太異想天開，稍微有一點變分法的概念即可。但是結果卻非常有趣。</p>
</section>
<section id="連續的版本-von-neumann-game" class="level3">
<h3 class="anchored" data-anchor-id="連續的版本-von-neumann-game">連續的版本 Von Neumann Game</h3>
<p>我們其實可以考慮一個更一般化的版本。</p>
<p>兩人各自從 <img src="https://latex.codecogs.com/png.latex?%5B0,1%5D"> 區間內抽取一個數字作為「牌面」，數字越大代表牌越強。</p>
<p>抽取的機率密度是均勻分布。</p>
<p>其他規則與上面相同。</p>
<p>這個版本其實是 John von Neumann 在 1928 年發表的經典論文 “Zur Theorie der Gesellschaftsspiele” 中所提出的「連續版本」(Continuous Version) 的博弈模型。</p>
<p>我們今天主要分析這個版本，但大家可以隨時切換，想像若是離散的版本推導會變成怎樣。</p>
</section>
<section id="策略表示法" class="level3">
<h3 class="anchored" data-anchor-id="策略表示法">策略表示法</h3>
<p>什麼是一個 Player A (或 B) 的「策略」呢？</p>
<p>就是要完整描述，Player A (或 B) 在每一種可能的「狀況」下，會採取什麼行動 (的機率分布)。</p>
<p>因為這個遊戲極其簡化，Player A 和 B 都各只有一個決策點 Figure&nbsp;1。</p>
<p>而這遊戲會面臨的狀況就是「自己拿到的牌是什麼數字」。完全看不到對手的牌。(看對手的面部表情算是 side information，不在這個模型裡面討論)</p>
<ul>
<li>Player A:
<ul>
<li>假設拿到的牌面是 <img src="https://latex.codecogs.com/png.latex?x%20%5Cin%20%5B0,1%5D">。</li>
<li>Player A 的策略可以表示為一個函數 <img src="https://latex.codecogs.com/png.latex?a(x)">，代表當拿到牌面 <img src="https://latex.codecogs.com/png.latex?x"> 時，Player A 選擇 <strong>下注 (Bet)</strong> 的機率。</li>
</ul></li>
<li>Player B:
<ul>
<li>假設拿到的牌面是 <img src="https://latex.codecogs.com/png.latex?y%20%5Cin%20%5B0,1%5D">。</li>
<li>Player B 的策略可以表示為一個函數 <img src="https://latex.codecogs.com/png.latex?b(y)">，代表當拿到牌面 <img src="https://latex.codecogs.com/png.latex?y"> 時，並且 Player A 已經下注 <img src="https://latex.codecogs.com/png.latex?B">，Player B 選擇 <strong>跟注 (Call)</strong> 的機率。</li>
<li>(注意，若 Player A 選擇過牌，則 Player B 也必須過牌，這個情況就跟 Player B 的策略無關了)</li>
</ul></li>
</ul>
<div id="fig-strategy-functions" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-strategy-functions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://your-website-url.example.com/posts/poker/images/lesson_6/strategy_functions.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-strategy-functions-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Strategy Functions
</figcaption>
</figure>
</div>
<p>當兩個 Player 的策略給定後，就可以算這個 game 的期望值了。</p>
<p>因為是個零和遊戲 (zero-sum game)，或者精確來說 和是 <img src="https://latex.codecogs.com/png.latex?P">。所以只要關注 Player A 的期望值 <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_A%5D"> 即可，Player B 的期望值就是 <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_B%5D%20=%20P%20-%20%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_A%5D">。</p>
</section>
<section id="player-a-的期望值" class="level3">
<h3 class="anchored" data-anchor-id="player-a-的期望值">Player A 的期望值</h3>
<p>如圖Figure&nbsp;1 所示，遊戲有三種結局，我們寫個表來看看他們分別對 Player A 的 payoff 是多少：</p>
<table class="caption-top table">
<colgroup>
<col style="width: 16%">
<col style="width: 26%">
<col style="width: 28%">
<col style="width: 28%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th>結局 1 <br> (強制攤牌)</th>
<th>結局 2 <br> (A 下注，B 跟注)</th>
<th>結局 3 <br> (A 下注，B 棄牌)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>若 <img src="https://latex.codecogs.com/png.latex?x%20%3E%20y"></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
<td><img src="https://latex.codecogs.com/png.latex?P%20+%20B"></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
</tr>
<tr class="even">
<td>若 <img src="https://latex.codecogs.com/png.latex?x%20=%20y"></td>
<td><img src="https://latex.codecogs.com/png.latex?P/2"></td>
<td><img src="https://latex.codecogs.com/png.latex?P/2"></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
</tr>
<tr class="odd">
<td>若 <img src="https://latex.codecogs.com/png.latex?x%20%3C%20y"></td>
<td><img src="https://latex.codecogs.com/png.latex?0"></td>
<td><img src="https://latex.codecogs.com/png.latex?-B"></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
</tr>
</tbody>
</table>
<p>稍微解釋一下:</p>
<ul>
<li>比方說 結局2 (<img src="https://latex.codecogs.com/png.latex?x%3Ey">) 的情況，Player A 最終會拿到的是 <img src="https://latex.codecogs.com/png.latex?P+2B">，但其中有 <img src="https://latex.codecogs.com/png.latex?B"> 是 Player A 自己下注的錢，而 <strong>此刻還沒被放進去</strong>，所以 payoff 只算 <img src="https://latex.codecogs.com/png.latex?P%20+%20B">。</li>
<li>當然，池底 <img src="https://latex.codecogs.com/png.latex?P"> 也有一半是 Player A 的錢。但那是已經放進去的，是 <strong>沉默成本</strong> 的概念，所以不會在 payoff 裡面扣掉。</li>
<li>若最終分析出來，Player A 的期望值小於 <img src="https://latex.codecogs.com/png.latex?P/2">，此時把放池底的 <img src="https://latex.codecogs.com/png.latex?P/2"> 算進去，整體期望值變成負的了! 那 Player A 就 不應該參與這個遊戲。也就是退回到「玩/不玩」 這個遊戲這個決策節點來思考，不玩的期望值就是單純的 0。當然，如果不玩會被女朋友罵的話，那就另當別論了。所以這個一個 local optimum 的分析</li>
</ul>
<p>因為是連續的均勻分布，所以 <img src="https://latex.codecogs.com/png.latex?x%20=%20y"> 的機率為 0，我們先忽略不計。但若是離散版本，則需要把平手的情況也考慮進去，因為此時若是結局 3，Player A 仍然賺到。</p>
<div id="fig-game-space" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-game-space-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://your-website-url.example.com/posts/poker/images/lesson_6/game_space_crosshair.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-game-space-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Game Space
</figcaption>
</figure>
</div>
<p><strong>積分表示法:</strong></p>
<p>當給了 <img src="https://latex.codecogs.com/png.latex?a(x)"> 與 <img src="https://latex.codecogs.com/png.latex?b(y)"> 後，這個遊戲的期望值就固定下來了: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A&amp;%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_A%5D%20:=%20%5Cmathcal%7BL%7D(a(x),%20b(y))%20%20%5C%5C%0A&amp;=%20%5Cint_0%5E1%20%5Cint_0%5E1%20%5CBigg%5B%20%5C%5C%0A&amp;%5Cquad%20(1%20-%20a(x))%20%5Ccdot%20P%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20%20&amp;%5Cqquad%5Ctext%7B(%E7%B5%90%E5%B1%80%201:%20Player%20A%20check)%7D%20%20%5C%5C%20%20%0A&amp;%5Cquad%20+%20a(x)%20%5Ccdot%20b(y)%20%5Ccdot%20(%20(P%20+%20B)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20+%20(-B)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20)%20%20%20&amp;%5Cqquad%5Ctext%7B(%E7%B5%90%E5%B1%80%202:%20Player%20A%20bet,%20Player%20B%20call)%7D%20%20%5C%5C%20%20%0A&amp;%5Cquad%20+%20a(x)%20%5Ccdot%20(1%20-%20b(y))%20%5Ccdot%20P%20%20%20&amp;%5Cqquad%5Ctext%7B(%E7%B5%90%E5%B1%80%203:%20Player%20A%20bet,%20Player%20B%20fold)%7D%20%20%5C%5C%0A&amp;%5Cquad%20%5CBigg%5D%20dy%20dx%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>我們用了 指示函數(indicator function): <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7B1%7D_%7Bx%3Ey%7D"> 來表示「牌面大小比較」的條件。當然，也可以寫成分段的積分，但這樣寫起來，簡直像是直接從上面的表格搬下來的一樣，清楚多了。</p>
<p>我們再寫一次表格形式:</p>
<table class="caption-top table">
<colgroup>
<col style="width: 16%">
<col style="width: 26%">
<col style="width: 28%">
<col style="width: 28%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th>結局 1 <br> (強制攤牌)</th>
<th>結局 2 <br> (A 下注，B 跟注)</th>
<th>結局 3 <br> (A 下注，B 棄牌)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>若 <img src="https://latex.codecogs.com/png.latex?x%20%3E%20y"></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
<td><img src="https://latex.codecogs.com/png.latex?P%20+%20B"></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
</tr>
<tr class="even">
<td>若 <img src="https://latex.codecogs.com/png.latex?x%20%3C%20y"></td>
<td><img src="https://latex.codecogs.com/png.latex?0"></td>
<td><img src="https://latex.codecogs.com/png.latex?-B"></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
</tr>
<tr class="odd">
<td><strong>機率密度</strong></td>
<td><img src="https://latex.codecogs.com/png.latex?1%20-%20a(x)"></td>
<td><img src="https://latex.codecogs.com/png.latex?a(x)%20%5Ccdot%20b(y)"></td>
<td><img src="https://latex.codecogs.com/png.latex?a(x)%20%5Ccdot%20(1%20-%20b(y))"></td>
</tr>
</tbody>
</table>
<p>好，現在 <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_A%5D%20=%20%5Cmathcal%7BL%7D(a(x),%20b(y))"> 是一個 <img src="https://latex.codecogs.com/png.latex?a(x)"> 與 <img src="https://latex.codecogs.com/png.latex?b(y)"> 的泛函 (functional)。</p>
<p>回顧 Min-Max 原理，Player A 的任務是調整 <img src="https://latex.codecogs.com/png.latex?a(x)"> 來<strong>最大化</strong> <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D">，而 Player B 的任務是調整 <img src="https://latex.codecogs.com/png.latex?b(y)"> 來<strong>最小化</strong> <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D">。</p>
<p>推導這個 Min-Max 解需要用到變分法的觀念，大概要花 20 分鐘的時間。</p>
<p>但我們先看一下這個式子。</p>
<p>回想上一篇中，調整 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 與 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 來最大化/最小化期望值的過程。</p>
<p>而現在我們要調整的，變成是無限維度的函數 <img src="https://latex.codecogs.com/png.latex?a(x)"> 與 <img src="https://latex.codecogs.com/png.latex?b(y)">。</p>
<p>若是離散版本，則可以把 <img src="https://latex.codecogs.com/png.latex?a(x)"> 與 <img src="https://latex.codecogs.com/png.latex?b(y)"> 就是定義在有限個點上的向量 (13維向量)，但記得討論相等 <img src="https://latex.codecogs.com/png.latex?(x=y)"> 的情況。</p>
<p>而我們在 Part2 中用了 Pure Strategy 的線性組合，發現了雙曲面和翹翹板的圖像。</p>
<p>但若要考慮所有 Pure Strategy 的凸包頂點，則是所有取值為 0 或 1 的函數 <img src="https://latex.codecogs.com/png.latex?a(x)"> 與 <img src="https://latex.codecogs.com/png.latex?b(y)">，那是 <img src="https://latex.codecogs.com/png.latex?2%5E%7B%5Cmathbb%7BR%7D%7D">。那行不通。</p>
<p>所以這邊翹翹板的圖像又變了。</p>
</section>
<section id="變分法" class="level3">
<h3 class="anchored" data-anchor-id="變分法">變分法</h3>
<p>我們回到 Lagrangian，並嘗試用變分法來解這個 Min-Max 問題。</p>
<p>將 <img src="https://latex.codecogs.com/png.latex?a(x)"> 想成已知，我們要找出 Player B 的最佳策略 <img src="https://latex.codecogs.com/png.latex?b(y)"> 來<strong>最小化</strong> <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D">。 重寫這個式子，將關於 <img src="https://latex.codecogs.com/png.latex?b(y)"> 的部分提出來: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathcal%7BL%7D(a(x),%20b(y))%0A=%20&amp;%20%5Cint_0%5E1%20%5Cint_0%5E1%20%5CBigg%5B%0A(1%20-%20a(x))%20%5Ccdot%20P%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20+%20a(x)%20%5Ccdot%20P%20%20%5C%5C%0A&amp;%5Cqquad%5Cqquad%20+%20%5Ctextcolor%7Bred%7D%7Bb(y)%7D%20%5Ccdot%20%5Cbigg(%0Aa(x)%20%5Ccdot%20(P%20+%20B)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20+%20a(x)%20%5Ccdot%20(-B)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%20-%20a(x)%20%5Ccdot%20P%0A%5Cbigg)%0A%5CBigg%5D%20dy%20dx%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>如果 <img src="https://latex.codecogs.com/png.latex?b(y)"> 要讓 <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BL%7D"> 最小化，則當 <img src="https://latex.codecogs.com/png.latex?b(y)"> 乘上的那個東西是負的時候，<img src="https://latex.codecogs.com/png.latex?b(y)"> 應該取最大值 1；反之，當那個東西是正的時候，<img src="https://latex.codecogs.com/png.latex?b(y)"> 應該取最小值 0。</p>
<p>所以其實 Player B 的最佳策略 <img src="https://latex.codecogs.com/png.latex?b(y)"> 會是個 Pure Strategy。</p>
<p>不過稍等一下，裡面那個東西跟 <img src="https://latex.codecogs.com/png.latex?x"> 有關，但 <img src="https://latex.codecogs.com/png.latex?b(y)"> 只能根據 <img src="https://latex.codecogs.com/png.latex?y"> 來決定，所以上述其實是對 <img src="https://latex.codecogs.com/png.latex?x"> 取平均的結果，也就是積分掉 <img src="https://latex.codecogs.com/png.latex?x">。</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathcal%7BL%7D(a(x),%20b(y))%0A=%20&amp;%20%5Cint_0%5E1%20%5Cint_0%5E1%20%5CBigg%5B%0A(1%20-%20a(x))%20%5Ccdot%20P%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20+%20a(x)%20%5Ccdot%20P%20%20%0A%5CBigg%5D%20dy%20dx%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cint_0%5E1%20%5Cint_0%5E1%20%5CBigg%5B%20%5Ctextcolor%7Bred%7D%7Bb(y)%7D%20%5Ccdot%20a(x)%20%5Cbigg(%0A(P%20+%20B)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20+%20(-B)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%20-%20P%0A%5Cbigg)%0A%5CBigg%5D%20dy%20dx%20%5C%5C%0A=%20&amp;%20%5Cint_0%5E1%20%5Cint_0%5E1%20%5CBigg%5B%0A(1%20-%20a(x))%20%5Ccdot%20P%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20+%20a(x)%20%5Ccdot%20P%20%20%0A%5CBigg%5D%20dy%20dx%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Bb(y)%7D%20%5Cleft(%20%5Cint_0%5E1%0Aa(x)%20%5Ccdot%20(%0A(P%20+%20B)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%20-%20P%0A)%5C,%20dx%0A%5Cright)%20dy%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>我們來看看 <img src="https://latex.codecogs.com/png.latex?b(y)"> 乘上的那個東西: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0Ah(y)%20:=%20&amp;%20%5Cint_0%5E1%20a(x)%20%5Ccdot%20(%20(P%20+%20B)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20B%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%20-%20P%20)%20%5C,%20dx%20%5C%5C%0A=%20&amp;%20%5Cint_0%5E1%20a(x)%20%5Ccdot%20(%20B%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20-%20(B+P)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%20)%20%5C,%20dx%20%5C%5C%0A=%20&amp;%20B%20%5Ccdot%20%5Cint_y%5E1%20a(x)%20%5C,%20dx%20-%20(P%20+%20B)%20%5Ccdot%20%5Cint_0%5Ey%20a(x)%20%5C,%20dx%20%20%5Ctag%7B1%7D%5Clabel%7Beq:hy_formula%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 也就是說將 <img src="https://latex.codecogs.com/png.latex?a(x)"> 小於 <img src="https://latex.codecogs.com/png.latex?y"> 的部分乘上 <img src="https://latex.codecogs.com/png.latex?-(P+B)"> 後，再加上大於 <img src="https://latex.codecogs.com/png.latex?y"> 的部分乘上 <img src="https://latex.codecogs.com/png.latex?B">，然後積分。</p>
<p>這個 <img src="https://latex.codecogs.com/png.latex?h(y)"> 會是個遞減函數: <img src="https://latex.codecogs.com/png.latex?%0Ah'(y)%20=%20-%20B%20%5Ccdot%20a(y)%20-%20(P%20+%20B)%20%5Ccdot%20a(y)%20=%20-%20(P%20+%202B)%20%5Ccdot%20a(y)%20%5Cleq%200%0A"> 而初始和末端值分別是: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Ah(0)%20=%20B%20%5Ccdot%20%5Cint_0%5E1%20a(x)%20%20%5C,%20dx%20%5Cgeq%200%20%5C%5C%0Ah(1)%20=%20-%20(P%20+%20B)%20%5Ccdot%20%5Cint_0%5E1%20a(x)%20%20%5C,%20dx%20%5Cleq%200%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>如圖Figure&nbsp;4 。</p>
<p>從 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hy_formula%7D"> 可以看出使 <img src="https://latex.codecogs.com/png.latex?h(y%5E*)%20=%200"> 的點 <img src="https://latex.codecogs.com/png.latex?y%5E*">，會滿足面積比公式 <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cint_0%5E%7By%5E*%7D%20a(x)%20%5C,%20dx%7D%7B%5Cint_%7By%5E*%7D%5E1%20a(x)%20%5C,%20dx%7D%20=%20%5Cfrac%7BB%7D%7BP%20+%20B%7D%20%20%5Ctag%7B2%7D%5Clabel%7Beq:area_ratio%7D%0A"></p>
<p>有了 <img src="https://latex.codecogs.com/png.latex?y%5E*"> 後，可以將 <img src="https://latex.codecogs.com/png.latex?h(y)"> 寫成 <img src="https://latex.codecogs.com/png.latex?%0Ah(y)%20=%20-(P+2B)%20%5Cint_%7By%5E*%7D%5Ey%20a(x)%20%5C,%20dx%20%20%5Ctag%7B3%7D%5Clabel%7Beq:hy_from_y_star%7D%0A"></p>
<div id="fig-bluff-value-ratio" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-bluff-value-ratio-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://your-website-url.example.com/posts/poker/images/lesson_6/bluff_value_ratio_2.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-bluff-value-ratio-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;4: <img src="https://latex.codecogs.com/png.latex?h(y)"> and <img src="https://latex.codecogs.com/png.latex?a(x)">
</figcaption>
</figure>
</div>
<p>帶回去 Lagrangian: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cmathcal%7BL%7D(a(x),%20b(y))%0A=%20&amp;%20%5Cint_0%5E1%20%5Cint_0%5E1%20%5CBigg%5B%0A(1%20-%20a(x))%20%5Ccdot%20P%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Ey%7D%20+%20a(x)%20%5Ccdot%20P%20%20%0A%5CBigg%5D%20dy%20dx%20+%20%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Bb(y)%7D%20%5Ccdot%20%5Ctextcolor%7Bgreen%7D%7Bh(y)%7D%20%5C,%20dy%20%5C%5C%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20P%20%5Ccdot%20%5Cint_0%5E1%20%5Cint_0%5E1%20%20a(x)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5C,%20dy%20dx%20+%20%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Bb(y)%7D%20%5Ccdot%20%5Ctextcolor%7Bgreen%7D%7Bh(y)%7D%20%5C,%20dy%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>這時開始使用 Min-Max 原理，來研究 Player B 的最佳<strong>進攻策略</strong> <img src="https://latex.codecogs.com/png.latex?b(y)">。</p>
<p>假設 Player B 可以知道 Player A 的策略 <img src="https://latex.codecogs.com/png.latex?a(x)">，根據上面 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:area_ratio%7D"> 算出來的 <img src="https://latex.codecogs.com/png.latex?y%5E*">，Player B 的最佳策略就是: <img src="https://latex.codecogs.com/png.latex?%0Ab(y)%20=%20%5Cbegin%7Bcases%7D%0A0,%20&amp;%20y%20%3C%20y%5E*%20%5C%5C%0A1,%20&amp;%20y%20%3E%20y%5E*%20%5C%5C%0A%5Cend%7Bcases%7D%0A"><br>
也就是說在一個閾值 (threshold) <img src="https://latex.codecogs.com/png.latex?y%5E*"> 之下，Player B 全部棄牌；在閾值 <img src="https://latex.codecogs.com/png.latex?y%5E*"> 之上，Player B 全部跟注。聽起來相當的合理。</p>
<p>而這個閾值 <img src="https://latex.codecogs.com/png.latex?y%5E*"> 是由 Player A 的策略 <img src="https://latex.codecogs.com/png.latex?a(x)"> 所決定的。其中切分點在將 <img src="https://latex.codecogs.com/png.latex?a(x)"> 之面積切分為 <img src="https://latex.codecogs.com/png.latex?B:(P+B)"> 的比例。</p>
<p>如果還記得前面的 lesson 4 和 5，跟當時的 bluff-to-value ratio 算出來一樣! 但我們還沒完全搞懂，暫且繼續看下去。</p>
<p>不論 Player A 下注機率分布 <img src="https://latex.codecogs.com/png.latex?a(x)"> 是什麼形狀，Player B 的最佳進攻策略是將其分成 <img src="https://latex.codecogs.com/png.latex?B:(P+B)"> 的比例的兩個區域，然後大的區域跟注，小的區域棄牌。仔細想想，還真的很不直觀。</p>
<p>對於 <img src="https://latex.codecogs.com/png.latex?b(y)"> 另一種寫法其實是: <img src="https://latex.codecogs.com/png.latex?%0Ab(y)%20=%20%5Cbegin%7Bcases%7D%0A0,%20&amp;%20h(y)%20%3E%200%20%5C%5C%0A1,%20&amp;%20h(y)%20%3C%200%20%5C%5C%0A%5Cend%7Bcases%7D%20%20%5Ctag%7B5%7D%5Clabel%7Beq:b_from_h%7D%0A"><br>
此時 <img src="https://latex.codecogs.com/png.latex?%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Bb(y)%7D%20%5Ccdot%20h(y)%20%5C,%20dy"> 取到的最小值就是 <img src="https://latex.codecogs.com/png.latex?%0A%5Cmin_%7B%5Ctextcolor%7Bred%7D%7Bb(y)%7D%7D%20%5Cint_0%5E1%20%5Ctextcolor%7Bred%7D%7Bb(y)%7D%20%5Ccdot%20h(y)%20%5C,%20dy%20=%20%5Cint_0%5E1%20%5Cmin(0,%20h(y))%20%5C,%20dy%0A"></p>
<p>那我們來算算右邊是多少(只跟 <img src="https://latex.codecogs.com/png.latex?a(x)"> 有關): <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cint_0%5E1%20%5Cmin(0,%20h(y))%20%5C,%20dy%0A=%20&amp;%20%5Cint_%7By%5E*%7D%5E1%20h(y)%20%5C,%20dy%20%20%5C%5C%0A=%20&amp;%20%5Cint_%7By%5E*%7D%5E1%20%5Cleft(%20-%20(P%20+%202B)%20%5Cint_%7By%5E*%7D%5Ey%20a(x)%20%5C,%20dx%20%5Cright)%20dy%20%20%5C%5C%20%20%0A=%20&amp;%20-%20(P%20+%202B)%20%5Cint_%7By%5E*%7D%5E1%20%5Cleft(%20%5Cint_%7By%5E*%7D%5Ey%20a(x)%20%5C,%20dx%20%5Cright)%20dy%20%20%5C%5C%0A=%20&amp;%20-%20(P%20+%202B)%20%5Cint_%7By%5E*%7D%5E1%20a(x)%20%5Cleft(%20%5Cint_x%5E1%20dy%20%5Cright)%20dx%20%20%20%5C%5C%0A=%20&amp;%20-%20(P%20+%202B)%20%5Cint_%7By%5E*%7D%5E1%20a(x)%20(1%20-%20x)%20%5C,%20dx%20%20%20%5Ctag%7B4%7D%5Clabel%7Beq:min_b_integral%7D%0A%5Cend%7Balign%7D%0A"> <img src="https://your-website-url.example.com/posts/poker/images/lesson_6/fubini_region.png" id="fig-fubini-region" class="img-fluid" alt="Fubini Integration Region"></p>
<p>帶回去 Lagrangian: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmin_%7Bb(y)%7D%20%5Cmathcal%7BL%7D(a(x),%20b(y))%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20P%20%5Ccdot%20%5Cint_0%5E1%20%5Cint_0%5E1%20%20a(x)%20%5Ccdot%20%5Cmathbb%7B1%7D_%7Bx%3Cy%7D%20%5C,%20dy%20dx%20+%20%5Cint_0%5E1%20%5Cmin(0,%20h(y))%20%5C,%20dy%20%5C%5C%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20P%20%5Ccdot%20%5Cint_0%5E1%20a(x)%20%5Cleft(%20%5Cint_x%5E1%20dy%20%5Cright)%20dx%20-%20(P%20+%202B)%20%5Cint_%7By%5E*%7D%5E1%20a(x)%20(1%20-%20x)%20%5C,%20dx%20%5C%5C%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20P%20%5Ccdot%20%5Cint_0%5E1%20a(x)%20(1%20-%20x)%20%5C,%20dx%20-%20(P%20+%202B)%20%5Cint_%7By%5E*%7D%5E1%20a(x)%20(1%20-%20x)%20%5C,%20dx%20%5C%5C%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20P%20%5Ccdot%20%5Cleft(%5Cint_0%5E%7By%5E*%7D%20a(x)%20(1%20-%20x)%20%5C,%20dx%20%5Cright)%20-%202B%20%5Ccdot%20%5Cleft(%5Cint_%7By%5E*%7D%5E1%20a(x)%20(1%20-%20x)%20%5C,%20dx%20%5Cright)%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<hr>
<p>直覺地來看一下這個式子。第一項 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7BP%7D%7B2%7D"> 是雙方放入的籌碼，後面兩項一正一負。注意其中的 <img src="https://latex.codecogs.com/png.latex?y%5E*"> 雖然是 Player B 的策略，但是是根據 <img src="https://latex.codecogs.com/png.latex?a(x)"> 來決定的，也就是把 <img src="https://latex.codecogs.com/png.latex?a(x)"> 底下的面積切分成 <img src="https://latex.codecogs.com/png.latex?B:(P+B)"> 的比例。假設固定這個 <img src="https://latex.codecogs.com/png.latex?y%5E*"> ，</p>
<ul>
<li>第二項是正的，代表 在 <img src="https://latex.codecogs.com/png.latex?%5Cint_0%5E%7By%5E*%7D%20a(x)"> 面積 固定之下，我們要最大化 <img src="https://latex.codecogs.com/png.latex?%5Cint_0%5E%7By%5E*%7D%20a(x)%20(1%20-%20x)%20%5C,%20dx">，也就是把 <img src="https://latex.codecogs.com/png.latex?a(x)"> 往左邊 (小牌面) 集中。</li>
<li>第三項是負的，代表 在 <img src="https://latex.codecogs.com/png.latex?%5Cint_%7By%5E*%7D%5E1%20a(x)"> 面積 固定之下，我們要最小化 <img src="https://latex.codecogs.com/png.latex?%5Cint_%7By%5E*%7D%5E1%20a(x)%20(1%20-%20x)%20%5C,%20dx">，也就是把 <img src="https://latex.codecogs.com/png.latex?a(x)"> 往右邊 (大牌面) 集中。</li>
</ul>
<p>所以結果變成</p>
<div id="fig-polarized-range" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-polarized-range-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://your-website-url.example.com/posts/poker/images/lesson_6/polarized_range_plot.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-polarized-range-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;5: Polarized Range
</figcaption>
</figure>
</div>
<p>但我們目前只知道比例 (<img src="https://latex.codecogs.com/png.latex?B:(P+B)">)，還有形狀 (往兩邊集中)，卻不知道具體值是多少。 所以要解 <img src="https://latex.codecogs.com/png.latex?a(x)"> 的 boundary 位置。</p>
<p>假設 boundary 分別在 <img src="https://latex.codecogs.com/png.latex?Bt"> 和 <img src="https://latex.codecogs.com/png.latex?1-(P+B)t">，則 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmin_%7Bb(y)%7D%20%5Cmathcal%7BL%7D(a(x),%20b(y))%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20P%20%5Ccdot%20%5Cleft(%5Cint_0%5E%7BBt%7D%20(1%20-%20x)%20%5C,%20dx%20%5Cright)%20-%202B%20%5Ccdot%20%5Cleft(%5Cint_%7B1-(P+B)t%7D%5E1%20(1%20-%20x)%20%5C,%20dx%20%5Cright)%20%5C%5C%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20P%20%5Ccdot%20%5Cleft(%20Bt%20-%20%5Cfrac%7B(Bt)%5E2%7D%7B2%7D%20%5Cright)%20-%202B%20%5Ccdot%20%5Cleft(%20%5Cfrac%7B(P+B)%5E2t%5E2%7D%7B2%7D%20%5Cright)%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>這是一個 <img src="https://latex.codecogs.com/png.latex?t"> 的二次函數，要最大化它，對 <img src="https://latex.codecogs.com/png.latex?t"> 微分並令其為零: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;P%20%5Ccdot%20%5Cleft(%20B%20-%20B%5E2%20t%20%5Cright)%20-%202B%20%5Ccdot%20(P%20+%20B)%5E2%20t%20=%200%20%5C%5C%0A%5Cimplies&amp;%5C,%20t%20=%20%5Cfrac%7BP%7D%7B2P%5E2%20+%205BP%20+%202B%5E2%7D%20=%20%5Cfrac%7BP%7D%7B(2P+B)(P+2B)%7D%20%20%5C%5C%0A%5Cimplies&amp;%5C,%20%5Ctext%7BLeft%20Boundary%7D%20=%20Bt%20=%20%5Ctextcolor%7Bdarkred%7D%7B%5Cfrac%7BBP%7D%7B(2P+B)(P+2B)%7D%7D%20%20%5C%5C%0A&amp;%5C,%20%5Ctext%7BRight%20Boundary%7D%20=%201%20-%20(P%20+%20B)t%20=%20%5Ctextcolor%7Bdarkred%7D%7B%5Cfrac%7BP%5E2+4BP+2B%5E2%7D%7B(2P+B)(P+2B)%7D%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>這就是 Player A 的最佳策略 <img src="https://latex.codecogs.com/png.latex?a(x)"> 的具體值了: <img src="https://latex.codecogs.com/png.latex?%0Aa(x)%20=%20%5Cbegin%7Bcases%7D%0A1,%20&amp;%200%20%5Cleq%20x%20%3C%20%5Cfrac%7BBP%7D%7B(2P+B)(P+2B)%7D%20%5C%5C%0A0,%20&amp;%20%5Cfrac%7BBP%7D%7B(2P+B)(P+2B)%7D%20%5Cleq%20x%20%5Cleq%20%5Cfrac%7BP%5E2+4BP+2B%5E2%7D%7B(2P+B)(P+2B)%7D%20%5C%5C%0A1,%20&amp;%20%5Cfrac%7BP%5E2+4BP+2B%5E2%7D%7B(2P+B)(P+2B)%7D%20%3C%20x%20%5Cleq%201%20%5C%5C%0A%5Cend%7Bcases%7D%0A"></p>
<p>而遊戲的 Game Value (期望值) 則是帶回去算: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmax_%7Ba(x)%7D%20%5Cmin_%7Bb(y)%7D%20%5Cmathcal%7BL%7D(a(x),%20b(y))%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20%5Cfrac%7B(PB)%5E2%7D%7B2(PB%5E2+2B(P+B)%5E2)%7D%20%5C%5C%0A=%20&amp;%20%5Cfrac%7BP%7D%7B2%7D%20+%20%5Cfrac%7BP%5E2%20B%7D%7B2(2P+B)(P+2B)%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>這也就是一開始提到的 Player A 的超額報酬!! 等於池底的一半，加上一個正數。</p>
<p><strong>小總結:</strong></p>
<p>這是 Player A 的最佳防守策略。若 Player A 固定這個策略，那根據 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:b_from_h%7D">，Player B 的策略在 <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7BBP%7D%7B(2P+B)(P+2B)%7D%20%3C%20y%20%3C%20%5Cfrac%7BP%5E2+4BP+2B%5E2%7D%7B(2P+B)(P+2B)%7D%0A"> 是如何都無所謂! 因為此時的 <img src="https://latex.codecogs.com/png.latex?h(y)%20=%200">。</p>
<p>回想一下剪刀石頭布，當對手強力防守時，我們有較大的容錯空間，不一定要準準的玩在 GTO 上，最終期望值也一樣。但其實 Player B 若要強力防守，那麼只有剛好一個 <img src="https://latex.codecogs.com/png.latex?y%5E*">，否則其他的 <img src="https://latex.codecogs.com/png.latex?y"> 都會露出破綻，讓 Player A 有剝削的空間。</p>
<!-- 
### 變分法 Part 2

前面是固定 Player A 的策略 $a(x)$，來求 Player B 的最佳策略 $b(y)$。然後再求 $a(x)$，這樣可以得到 Player A 的最佳防守策略 (GTO)，和 Player B 的最佳進攻策略。

現在反過來，固定 Player B 的策略 $b(y)$，來求 Player A 的最佳策略 $a(x)$。我們可以算 Player B 的最佳防守策略 (GTO)，和 Player A 的最佳進攻策略。
 -->


</section>

 ]]></description>
  <category>Poker</category>
  <guid>https://your-website-url.example.com/posts/poker/lesson_6_comparison.html</guid>
  <pubDate>Sat, 13 Dec 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>Poker Lesson 5 - 雙曲面 Payoff</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/poker/lesson_5_hyperbolic_payoff.html</link>
  <description><![CDATA[ 



<p>來延續上一篇的設定，假設 A 跟 B 玩 Seven-card stud， <img src="https://latex.codecogs.com/png.latex?40-80"> 元有限注，池底有 <img src="https://latex.codecogs.com/png.latex?P%20=%20100"> 元。</p>
<p>現在來到最後一輪 River 下注(已經發了最後一張牌)，前六張都是開的，最後一張只有自己知道。</p>
<ul>
<li>A 的手牌是: A♠ A♣ K♣ 9♦ 7♦ 6♥ [?]</li>
<li>B 的手牌是: K♠ 9♠ 8♠ 7♠ 4♦ 2♦ [?]</li>
</ul>
<p>Player A 先手應該要 pass。</p>
<p>輪到 Player B:</p>
<ul>
<li>若有 Nuts (湊成黑桃同花) 就一下會下注；</li>
<li>若是 Air 則要用 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 的機率決定是否詐唬 (下注 <img src="https://latex.codecogs.com/png.latex?B%20=%2080"> 元)。</li>
</ul>
<p>上一篇用了完整的機率算法，解出 <img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cbeta%20=%20%5Cfrac%7BrB%7D%7B(1-r)(B+P)%7D"> 是 Player B 的最佳防禦策略，其中 <img src="https://latex.codecogs.com/png.latex?r=1/5"> 是 Player B 拿到 Nuts 的機率 (從 Player A 的視角來看)。</p>
<p>而當 Player B bet時，Player A 的最佳回應策略是以 <img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Calpha%20=%20%5Cfrac%7BP%7D%7BB+P%7D"> 的機率去跟注。</p>
<p>今天來用另一種方式，本質上是一樣，但是可能省去了複雜的期望值計算，並且提供了更直觀的心智模型。</p>
<section id="翹翹板-payoff" class="level3">
<h3 class="anchored" data-anchor-id="翹翹板-payoff">翹翹板 Payoff</h3>
<p>我們說要考慮 Player A 對於 Player B 的下注時的回應，要以 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 的機率來決定是否跟注 (call <img src="https://latex.codecogs.com/png.latex?C%20=%2080"> 元)。</p>
<p>這邊兩個機率 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 跟 <img src="https://latex.codecogs.com/png.latex?%5Cbeta">，若直接硬算，那就會是跟上一篇一樣。但是其實只要算 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20%7B0,%201%7D">, <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%20%7B0,%201%7D"> 四種極端情況即可，因為剩下的情況會是這兩種的 <strong>mixed strategy</strong>。</p>
<ul>
<li><p>若 Player B 拿到 Nuts，則 B 一定會 bet。在兩種極端狀況下，Player A 的期望值 payoff：</p>
<table class="table">
<colgroup>
<col style="width: 39%">
<col style="width: 29%">
<col style="width: 30%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th>Player A: Always Fold <br> (<img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%200">)</th>
<th>Player A: Always Call <br> (<img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%201">)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>Player B: Always Bet</strong></td>
<td><img src="https://latex.codecogs.com/png.latex?0"></td>
<td><img src="https://latex.codecogs.com/png.latex?-B"></td>
</tr>
</tbody>
</table></li>
<li><p>若 Player B 拿到 Air。在四種極端狀況下，Player A 的期望值 payoff：</p>
<table class="table">
<colgroup>
<col style="width: 48%">
<col style="width: 25%">
<col style="width: 26%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th>Player A: Always Fold <br> (<img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%200">)</th>
<th>Player A: Always Call <br> (<img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%201">)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>Player B: Always Bet (<img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%201">)</strong></td>
<td><img src="https://latex.codecogs.com/png.latex?0"></td>
<td><img src="https://latex.codecogs.com/png.latex?B%20+%20P"></td>
</tr>
<tr class="even">
<td><strong>Player B: Always Check (<img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%200">)</strong></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
<td><img src="https://latex.codecogs.com/png.latex?P"></td>
</tr>
</tbody>
</table></li>
</ul>
<p>我們將以上三種情況，分別畫下來：</p>
<ul>
<li>Senario 1: Player B 拿到 Nuts，則 Player B 一定下注 (value bet)</li>
<li>Senario 2: Player B 拿到 Air，假設 Player B 總是下注 (bluff bet)</li>
<li>Senario 3: Player B 拿到 Air，假設 Player B 總是過牌 (honest check)</li>
</ul>
<p>那麼對 Player A 來說，這三種情況的 payoff 分別是：</p>
<div id="fig-lesson5-seesaw" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/poker/images/visualize_seesaw.png" class="img-fluid figure-img"></p>
<figcaption class="figure-caption">Figure&nbsp;1: Seesaw Payoff</figcaption>
</figure>
</div>
<p>因為 Player A 要最大化 payoff，所以會選數值大的 (翹翹板高處)。</p>
<p>先讓我們暫時把這三個翹翹板記在心中，待會再回來看。</p>
</section>
<section id="雙曲面" class="level3">
<h3 class="anchored" data-anchor-id="雙曲面">雙曲面</h3>
<p>假設 Player B 拿到 Nuts 的機率是 <img src="https://latex.codecogs.com/png.latex?r"> (此處 <img src="https://latex.codecogs.com/png.latex?r=1/5">)，那麼一個 average over Player B 手牌的 Player A payoff 表格，即是兩個表的加權平均：</p>
<table class="table">
<colgroup>
<col style="width: 48%">
<col style="width: 25%">
<col style="width: 26%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th>Player A: Always Fold <br> (<img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%200">)</th>
<th>Player A: Always Call <br> (<img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%201">)</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong>Player B: Always Bet (<img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%201">)</strong></td>
<td><img src="https://latex.codecogs.com/png.latex?0"></td>
<td><img src="https://latex.codecogs.com/png.latex?-rB%20+%20(1-r)(B+P)"></td>
</tr>
<tr class="even">
<td><strong>Player B: Always Check (<img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%200">)</strong></td>
<td><img src="https://latex.codecogs.com/png.latex?(1-r)P"></td>
<td><img src="https://latex.codecogs.com/png.latex?-rB%20+%20(1-r)P"></td>
</tr>
</tbody>
</table>
<p>先來簡化一下符號，將上面的 payoff 寫成矩陣 <img src="https://latex.codecogs.com/png.latex?X%20=%20%5BX_%7B%5Cbeta%20%5Calpha%7D%5D">：</p>
<table class="table">
<thead>
<tr class="header">
<th></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%200"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%201"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td><strong><img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%201"></strong></td>
<td><img src="https://latex.codecogs.com/png.latex?X_%7B10%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?X_%7B11%7D"></td>
</tr>
<tr class="even">
<td><strong><img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%200"></strong></td>
<td><img src="https://latex.codecogs.com/png.latex?X_%7B00%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?X_%7B01%7D"></td>
</tr>
</tbody>
</table>
<p>在這個例子中是 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0AX_%7B10%7D%20&amp;%20=%200%20%5C%5C%0AX_%7B11%7D%20&amp;%20=%20-rB%20+%20(1-r)(B+P)%20%5C%5C%0AX_%7B00%7D%20&amp;%20=%20(1-r)P%20%5C%5C%0AX_%7B01%7D%20&amp;%20=%20-rB%20+%20(1-r)P%0A%5Cend%7Balign%7D%0A"></p>
<p>既然已經知道 Pure Strategy 的 <strong>所有可能</strong> 情況，那麼 mix strategy 就是這些情況的 convex linear combination，而 <img src="https://latex.codecogs.com/png.latex?%5Calpha,%20%5Cbeta%20%5Cin%20%5B0,%201%5D"> 就是權重。</p>
<p>所以在 mix strategy 時， Player A 的 payoff 期望值就是： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_A%5D%20&amp;%20=%20%5Calpha%20%5Cbeta%20X_%7B11%7D%20+%20%5Calpha%20(1-%5Cbeta)%20X_%7B01%7D%20+%20(1-%5Calpha)%20%5Cbeta%20X_%7B10%7D%20+%20(1-%5Calpha)(1-%5Cbeta)%20X_%7B00%7D%20%20%5Ctag%7B1%7D%5Clabel%7Beq:hyperbolic_payoff%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>將 <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_A%5D"> 視為一個 <img src="https://latex.codecogs.com/png.latex?%5Calpha,%20%5Cbeta"> 的函數，畫在三維空間中的話，就是一個雙曲面 (hyperbolic surface)：</p>
<div id="fig-lesson5-hyperbolic_heatmap" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/poker/images/hyperbolic_heatmap.png" class="img-fluid figure-img"></p>
<figcaption class="figure-caption">Figure&nbsp;2: Hyperbolic Payoff Surface</figcaption>
</figure>
</div>
<p>這是一個標準的雙曲面 (hyperbolic paraboloid)，中間有個鞍點 (saddle point)。</p>
<p>雖然是個二次函數，但當固定其中一個變數 (例如 <img src="https://latex.codecogs.com/png.latex?%5Cbeta">)，截面其實是一條直線。可以將雙曲面想成是一條直線一邊旋轉一邊平移所掃出來的曲面。</p>
<p>當我們看 Side View 時 (相 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 這個維度投影掉)，可以明顯看出這個直線掃出的感覺，這不就是剛剛的翹翹板? 沒錯，這個雙曲面其實就是把三個翹翹板「合體」起來的結果。</p>
<p>讓我們 zoom in 看一下這個投影在 <img src="https://latex.codecogs.com/png.latex?%5Calpha">-<img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 平面圖，其實也就是把 payoff 畫成 heatmap：</p>
<div id="fig-lesson5-payoff_landscape" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/poker/images/payoff_landscape.png" class="img-fluid figure-img"></p>
<figcaption class="figure-caption">Figure&nbsp;3: 2D Payoff Surface - Heatmap</figcaption>
</figure>
</div>
<p>這張圖 Figure&nbsp;3 很視覺化了驗證了之前推導的結果:</p>
<ul>
<li>當 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20%5Calpha%5E*%20=%20%5Cfrac%7BP%7D%7BB+P%7D"> 時， 不管 Player B 選擇哪個，期望值都是一樣的 (白色區域)。</li>
<li>而當 <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%20%5Cbeta%5E*%20=%20%5Cfrac%7BrB%7D%7B(1-r)(B+P)%7D"> 時， 不管 Player A 選擇哪個，期望值也是一樣的 (白色區域)。</li>
<li>而當其中有人偏離平衡點時，另一人可以取 0 或 1 的極端策略來懲罰對方 (payoff 變成紅色或藍色)。</li>
</ul>
</section>
<section id="一般式" class="level3">
<h3 class="anchored" data-anchor-id="一般式">一般式</h3>
<p>現在幾何直覺已經很清楚了，讓我們回到一般式 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hyperbolic_payoff%7D">，來算一下公式解。</p>
<p>首先，這個鞍點會在 <img src="https://latex.codecogs.com/png.latex?%5Calpha,%20%5Cbeta%20%5Cin%20(0,%201)"> 內部出現的充要條件是： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A(X_%7B00%7D%20-%20X_%7B01%7D)(X_%7B10%7D%20-%20X_%7B11%7D)%20&amp;%20%3C%200%20%20%5C%5C%0A(X_%7B00%7D%20-%20X_%7B10%7D)(X_%7B01%7D%20-%20X_%7B11%7D)%20&amp;%20%3C%200%0A%5Cend%7Balign%7D%0A"> 也就是在端點時，兩條斜率相乘是負的。</p>
<p>而在此時，鞍點的位置 <img src="https://latex.codecogs.com/png.latex?(%5Calpha%5E*,%20%5Cbeta%5E*)"> 是： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Calpha%5E*%20&amp;%20=%20%5Cfrac%7BX_%7B00%7D%20-%20X_%7B10%7D%7D%7BX_%7B00%7D%20-%20X_%7B01%7D%20-%20X_%7B10%7D%20+%20X_%7B11%7D%7D%20%5C%5C%0A%5Cbeta%5E*%20&amp;%20=%20%5Cfrac%7BX_%7B00%7D%20-%20X_%7B01%7D%7D%7BX_%7B00%7D%20-%20X_%7B10%7D%20-%20X_%7B01%7D%20+%20X_%7B11%7D%7D%0A%5Cend%7Balign%7D%0A"> 這可以有很多種解法，其中一種直覺 (圖解法) 是讓 <img src="https://latex.codecogs.com/png.latex?%0A%5Calpha%20:%20(1%20-%20%5Calpha)%20=%20X_%7B00%7D%20-%20X_%7B10%7D%20:%20X_%7B11%7D%20-%20X_%7B01%7D%0A"></p>
<p>而這個鞍點的 payoff ，也就是這個 game 的 value 是： <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbb%7BE%7D%5B%5Ctext%7BPayoff%7D_A%5D%5E*%20=%20%5Cfrac%7BX_%7B00%7D%20X_%7B11%7D%20-%20X_%7B01%7D%20X_%7B10%7D%7D%7BX_%7B00%7D%20-%20X_%7B01%7D%20-%20X_%7B10%7D%20+%20X_%7B11%7D%7D%0A"></p>
<p>這當然也有很多種解法，例如直接把 <img src="https://latex.codecogs.com/png.latex?%5Calpha%5E*,%20%5Cbeta%5E*"> 帶回去。但另外一個有趣的算法是，若同時扣掉 <img src="https://latex.codecogs.com/png.latex?h"> 將這個鞍點的高度(垂直平移到0)的話，那雙曲面函數 兩組對角線項 相乘會相等: <img src="https://latex.codecogs.com/png.latex?%0A(X_%7B00%7D%20-%20h)(X_%7B11%7D%20-%20h)%20=%20(X_%7B01%7D%20-%20h)(X_%7B10%7D%20-%20h)%0A"><br>
這樣自動就解出鞍點的高度 <img src="https://latex.codecogs.com/png.latex?h"> 了。</p>
</section>
<section id="講回翹翹板" class="level3">
<h3 class="anchored" data-anchor-id="講回翹翹板">講回翹翹板</h3>
<p>我們再次回到翹翹板的圖像，原本翹翹板中間的桿子是沒有實質意義的，但現在剛好可以想成是線性的插值。</p>
<p><img src="https://your-website-url.example.com/posts/poker/images/visualize_seesaw.png" class="img-fluid"></p>
<table class="table">
<thead>
<tr class="header">
<th></th>
<th>Senario 1</th>
<th>Senario 2</th>
<th>Senario 3</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>直觀解釋</td>
<td>Value Bet</td>
<td>Bluff Bet</td>
<td>Honest Check</td>
</tr>
<tr class="even">
<td><strong>發生的機率</strong></td>
<td><img src="https://latex.codecogs.com/png.latex?r"></td>
<td><img src="https://latex.codecogs.com/png.latex?(1-r)%5Cbeta"></td>
<td><img src="https://latex.codecogs.com/png.latex?(1-r)(1-%5Cbeta)"></td>
</tr>
<tr class="odd">
<td>翹翹板</td>
<td><img src="https://latex.codecogs.com/png.latex?0:-B"></td>
<td><img src="https://latex.codecogs.com/png.latex?0:(B+P)"></td>
<td><img src="https://latex.codecogs.com/png.latex?P:P"></td>
</tr>
</tbody>
</table>
<p>而 Player B 的最佳策略，就是使得 Player A 感受到翹翹板是平衡的 (這就是無差異原則!)，也就是用機率加權後是平衡的。</p>
<p>於是我們再次推導出 bluff-to-value ratio: <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cmathbb%7BP%7D%5B%5Ctext%7Bbluff%7D%5D%7D%7B%5Cmathbb%7BP%7D%5B%5Ctext%7Bvalue%7D%5D%7D%20=%20%5Cfrac%7B(1-r)%5Cbeta%7D%7Br%7D%20=%20%5Cfrac%7BB%7D%7BB+P%7D%0A"> 因為第三種狀況是 balanced，所以不用考慮。</p>


</section>

 ]]></description>
  <category>Poker</category>
  <guid>https://your-website-url.example.com/posts/poker/lesson_5_hyperbolic_payoff.html</guid>
  <pubDate>Fri, 05 Dec 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>Poker Lesson 4 - 如何詐唬</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/poker/lesson_4_bluff_value_ratio.html</link>
  <description><![CDATA[ 




<p>在德州撲克中，有三種不確定性來源:</p>
<ul>
<li>你不知道對手的底牌是什麼</li>
<li>你不知道接下來會發什麼公共牌</li>
<li>你不知道對手會怎麼玩 (是否在詐唬)</li>
</ul>
<p>由於不確定性太多，甚至可能有多名玩家，狀況難以分析。</p>
<p>讓我們來考慮最簡單的版本之一: 只有兩名玩家 A 跟 B，而且 B 有完全的資訊(B知道自己輸還贏)，但 A 沒有任何資訊。</p>
<section id="seven-card-stud" class="level2">
<h2 class="anchored" data-anchor-id="seven-card-stud">Seven-card stud</h2>
<p>假設 A 跟 B 玩 Seven-card stud， <img src="https://latex.codecogs.com/png.latex?40-80"> 元有限注，池底有 <img src="https://latex.codecogs.com/png.latex?P%20=%20655"> 元。</p>
<p>現在來到最後一輪下注(已經發了最後一張牌)，前六張都是開的，最後一張只有自己知道。</p>
<ul>
<li>A 的手牌是: A♠ A♣ K♣ 9♦ 7♦ 6♥ [?]</li>
<li>B 的手牌是: K♠ 9♠ 8♠ 7♠ 4♦ 2♦ [?]</li>
</ul>
<div id="fig-seven-card-stud" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-seven-card-stud-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://your-website-url.example.com/posts/poker/images/poker_L4_page.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-seven-card-stud-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Seven-card stud
</figcaption>
</figure>
</div>
<p>目前 A 有一對 A，B 有高牌 K。若 B 的最後一張牌沒能組成同花 (flush)，那麼 A 就會贏。若 B 可以組成同花，那麼 A 也不可以組出更強的牌，所以 B 會贏。</p>
<p>也就是說，B 知道自己有沒有贏，但是 A 完全不知道。</p>
<p>現在這輪下注由 A 先行，他可以選擇下注 <img src="https://latex.codecogs.com/png.latex?B%20=%2080"> 元 (Bet size) 或是蓋牌 (fold)。</p>
<p>從旁觀者的角度: B 拿到同花的機率是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B8%7D%7B40%7D%20=%20%5Cfrac%7B1%7D%7B5%7D">，因為剩下的 40 張牌中，有 8 張黑桃可以讓 B 組成同花。</p>
<p><strong>A 的策略:</strong></p>
<p>A 應該先過 (check)。因為 A 沒有任何 B 不知道的資訊。</p>
<p>這無關 A 的勝率 (B拿到同花的機率)，因為只要 B 用誠實的策略 (若贏就下注，若輸就蓋牌)，A 最多只贏 <img src="https://latex.codecogs.com/png.latex?655"> 元，但下注的話多了輸 <img src="https://latex.codecogs.com/png.latex?80"> 元的風險。</p>
<p><strong>B 的策略:</strong></p>
<p>現在輪到 B。 B 已經知道自己是否會贏。</p>
<ul>
<li>如果 B 有同花(必贏)，那麼 B 當然要下注 <img src="https://latex.codecogs.com/png.latex?B%20=%2080"> 元。</li>
<li>如果 B 沒有同花(必輸)，B 應該下注嗎? 有那麼一點可能是下注可以騙到 A 蓋牌(fold)，那麼 B 就成功騙贏 <img src="https://latex.codecogs.com/png.latex?655"> 元。若欺騙失敗的話則多花 <img src="https://latex.codecogs.com/png.latex?80"> 元。</li>
</ul>
<p>B 的最佳策略是什麼呢?</p>
<section id="引入機率模型" class="level3">
<h3 class="anchored" data-anchor-id="引入機率模型">引入機率模型</h3>
<p>在真實世界中，我們當然都是進行有限次的比賽，這一輪的決定很可能跟前幾輪有關，也就是心理戰。但我們先不談有限次比賽，我們使用比較好分析的 無限次比賽 (infinite repeated game) 模型，也就是機率模型。根據中央極限定理，獨立地在一樣情況下進行無限次的抽樣，樣本平均值會趨近於期望值 (expected value)。所以我們只要最大化期望值就可以了。</p>
<p>所以假設有個機率 <img src="https://latex.codecogs.com/png.latex?%5Cbeta">，代表 B 在沒有同花的情況下，會以機率 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 詐唬 (下注 <img src="https://latex.codecogs.com/png.latex?B%20=%2080"> 元)。</p>
<p>我們就變成問，<img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 要取多少，才可以使得 B 的期望值最大化?</p>
<p>怎麼算期望值呢?</p>
<p>B bet 之後不知道 A 會 fold 還是 call，所以我們也要把 A 也拉入我們的機率模型，假設 A 會以 機率 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 跟注 (call)。</p>
<p><strong>B 的期望值計算:</strong></p>
<p>假設 Bet size &nbsp;<img src="https://latex.codecogs.com/png.latex?B%20=%2080"> 元，池底大小 <img src="https://latex.codecogs.com/png.latex?P%20=%20655"> 元。</p>
<p>使用全概率公式 (law of total expectation)，我們可以把 B 的期望值拆成以下幾項:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B)%0A&amp;=%20%5Cmathbb%7BP%7D%5B%5Ctext%7BB%20%E6%9C%89%E5%90%8C%E8%8A%B1,%20A%20call%7D%5D%20%5Ccdot%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B%20%7C%20%5Ctext%7BB%20%E6%9C%89%E5%90%8C%E8%8A%B1,%20A%20call%7D)%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cmathbb%7BP%7D%5B%5Ctext%7BB%20%E6%9C%89%E5%90%8C%E8%8A%B1,%20A%20fold%7D%5D%20%5Ccdot%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B%20%7C%20%5Ctext%7BB%20%E6%9C%89%E5%90%8C%E8%8A%B1,%20A%20fold%7D)%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cmathbb%7BP%7D%5B%5Ctext%7BB%20%E7%84%A1%E5%90%8C%E8%8A%B1,%20B%20bet,%20A%20call%7D%5D%20%5Ccdot%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B%20%7C%20%5Ctext%7BB%20%E7%84%A1%E5%90%8C%E8%8A%B1,%20B%20bet,%20A%20call%7D)%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cmathbb%7BP%7D%5B%5Ctext%7BB%20%E7%84%A1%E5%90%8C%E8%8A%B1,%20B%20bet,%20A%20fold%7D%5D%20%5Ccdot%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B%20%7C%20%5Ctext%7BB%20%E7%84%A1%E5%90%8C%E8%8A%B1,%20B%20bet,%20A%20fold%7D)%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cmathbb%7BP%7D%5B%5Ctext%7BB%20%E7%84%A1%E5%90%8C%E8%8A%B1,%20B%20check%7D%5D%20%5Ccdot%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B%20%7C%20%5Ctext%7BB%20%E7%84%A1%E5%90%8C%E8%8A%B1,%20B%20check%7D)%20%5C%5C%0A&amp;=%20%C2%A0%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft%5B%20%5Calpha%20%5Ccdot%20(P+B)%20+%20(1-%5Calpha)%20%5Ccdot%20P%20%5Cright%20%5D%0A%C2%A0%20+%20%5Cfrac%7B4%7D%7B5%7D%20%5Ccdot%20%5Cleft%5B%20%5Cbeta%20%5Ccdot%20%5Cleft(%20%5Calpha%20%5Ccdot%20(-B)%20+%20(1-%5Calpha)%20%5Ccdot%20P%20%5Cright)%20+%20(1-%5Cbeta)%20%5Ccdot%200%20%5Cright%5D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft%5B%20%5Calpha%20B%20+%20P%20%5Cright%20%5D%20+%20%5Cfrac%7B4%7D%7B5%7D%20%5Ccdot%20%5Cbeta%20%5Ccdot%20%5Cleft(%20-%5Calpha%20B%20+%20P%20-%20%5Calpha%20P%20%5Cright)%20%C2%A0%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft(%20%5Calpha%20B%20+%20P%20%5Cright)%20+%20%5Cbeta%20%5Cleft(%20%5Cfrac%7B4%7D%7B5%7D%20%5Cleft(%20-%5Calpha%20(B+P)%20+%20P%20%5Cright)%20%5Cright)%20%C2%A0%5Ctag%7B1%7D%5Clabel%7Beq:E_for_beta%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B5%7D%20P%20%5Cleft(%201%20+%204%5Cbeta%20%5Cright)%20+%20%5Calpha%20%5Cleft(%20%5Cfrac%7BB%7D%7B5%7D%20-%20%5Cfrac%7B4%7D%7B5%7D%20%5Cbeta%20(B%20+%20P)%20%5Cright)%20%C2%A0%5Ctag%7B2%7D%5Clabel%7Beq:E_for_alpha%7D%20%C2%A0%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>上面的推導中用到了 A 選擇 call 或 fold 的機率，跟 B 的狀態是獨立的，機率是相乘，因為 A 沒有任何資訊。</p>
<p>在真實世界中，雙方是不會知道對方的策略的。所以 A 不知道 B 的 <img src="https://latex.codecogs.com/png.latex?%5Cbeta">，B 也不知道 A 的 <img src="https://latex.codecogs.com/png.latex?%5Calpha">。</p>
<p>在這樣的情況下，A 要選一個 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 來最小化 B 的期望值，B 也要選一個 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 來最大化自己的期望值。</p>
<p>也就是說 B 的最佳 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 是多少，跟 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 有關；A 的最佳 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 也跟 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 有關。</p>
<p><strong>剪刀石頭布</strong></p>
<p>回想一下，這感覺跟在玩剪刀石頭布很像。我要出甚麼 (使用甚麼策略)，非常依賴於對方會出甚麼 (使用甚麼策略)。</p>
<p>假設我發現對方很常出 布，那我多出一些 剪刀 就可以贏更多。</p>
<p>但是對方發現我很常出 剪刀，那他多出一些 石頭 就可以贏我更多。</p>
<p>如果用各 1/3 的機率玩，那是最安全的，但是也完全佔不到便宜。(比方說對方就算永遠出布，長期而言期望值還是0)。</p>
<p>而當我發現對方的弱點，想要調整策略去佔便宜時，同時也會暴露出弱點。</p>
<p>這邊隱隱約約感覺到有兩種「最好 (optimal)」 的概念:</p>
<ol type="1">
<li>第一種是最好的<strong>防守</strong>策略，對方就算知道我的策略，也無法剝削我。</li>
<li>第二種是最好的<strong>進攻</strong>策略，假設我已知對方策略時，可以最大化剝削對方。</li>
</ol>
<p>由以上討論，我們發現當剪刀石頭布對手不是出均勻分布時，我們可以進攻，但是無法防守；若要繼續維持最佳防守，我們就無法進攻。</p>
</section>
<section id="納許均衡-nash-equilibrium" class="level3">
<h3 class="anchored" data-anchor-id="納許均衡-nash-equilibrium">納許均衡 (Nash Equilibrium)</h3>
<p>我們一般來說的「最佳策略 (optimal strategy)」是指 <strong>最佳防守策略</strong>，也就是無法被對方剝削的策略。</p>
<p>假設用 <img src="https://latex.codecogs.com/png.latex?%5Csigma_A"> 跟 <img src="https://latex.codecogs.com/png.latex?%5Csigma_B"> 分別代表 A 跟 B 的策略 (strategy)，可以用以下 Min-Max 定義出來: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Csigma_A%5E*%20:=%20%5Carg%20%5Cmax_%7B%5Csigma_A%7D%20%5Cmin_%7B%5Csigma_B%7D%20%5Cmathbb%7BE%7D(%5Ctext%7BA's%20payoff%7D%20%5Cmid%20%5Csigma_A,%20%5Csigma_B)%20%20%5Ctag%7BMin-Max%20Optimal%7D%5Clabel%7Beq:define_optimal%7D%20%5C%5C%0A%5Csigma_B%5E*%20:=%20%5Carg%20%5Cmax_%7B%5Csigma_B%7D%20%5Cmin_%7B%5Csigma_A%7D%20%5Cmathbb%7BE%7D(%5Ctext%7BB's%20payoff%7D%20%5Cmid%20%5Csigma_A,%20%5Csigma_B)%20%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 值得留意的是，這邊的期望值是跑遍所有可能的隨機性 (包含自己和對方的策略隨機性、以及遊戲本身的隨機性)。我們可以決定我們遇到某種狀況時要以怎樣的<strong>機率分布</strong>採取某種行動 (action)，但無法決定我們會遇到什麼狀況 (situation)。</p>
<p>而納許均衡的定義，是使用<strong>最佳進攻</strong>的概念：</p>
<p>對於 A 的納許均衡策略 <img src="https://latex.codecogs.com/png.latex?%5Csigma_A%5E*">，以及 B 的納許均衡策略 <img src="https://latex.codecogs.com/png.latex?%5Csigma_B%5E*">，有： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_A%20%7C%20%5Csigma_A%5E*,%20%5Csigma_B%5E*)%20&amp;%5Cge%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_A%20%7C%20%5Csigma_A,%20%5Csigma_B%5E*)%20%5Cquad%20%5Cforall%20%5Csigma_A%20%20%5Ctag%7BNash%20Equilibrium%7D%5Clabel%7Beq:nash_equilibrium%7D%20%5C%5C%20%20%0A%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B%20%7C%20%5Csigma_A%5E*,%20%5Csigma_B%5E*)%20&amp;%5Cge%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B%20%7C%20%5Csigma_A%5E*,%20%5Csigma_B)%20%5Cquad%20%5Cforall%20%5Csigma_B%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>首先先說明幾個重點:</p>
<ol type="1">
<li>納許均衡是描述一個 strategy pair <img src="https://latex.codecogs.com/png.latex?(%5Csigma_A%5E*,%20%5Csigma_B%5E*)">，而不是單一策略。</li>
<li>納許均衡可能不只有一組，但在有限賽局中引入混合策略 (mixed strategies) 後，一定存在。</li>
<li><strong>純策略與混合策略</strong>：若說 Pure Nash Equilibrium，代表策略是確定性的 (deterministic)；若說 Mixed Nash Equilibrium，代表策略是隨機性的 (stochastic)。</li>
</ol>
<p><strong>零和賽局 (Zero-Sum Game) 的美好性質</strong>:</p>
<blockquote class="blockquote">
<p>在零和賽局中，Min-Max 定理 (Minimax Theorem) 告訴我們 納許均衡策略 <img src="https://latex.codecogs.com/png.latex?%5Ciff"> 最佳防守策略 (Min-Max Optimal)</p>
</blockquote>
<p>這意味著在撲克這種零和遊戲裡，只要我們找到了讓對手「無利可圖」的防守策略，該策略同時也會是對抗高手的最佳策略。且無論這場賽局有多少個均衡點，雙方的期望收益 (Game Value) 都是唯一的。</p>
<p>雖然我們的賽局不是嚴格的零和賽局，但總和 <img src="https://latex.codecogs.com/png.latex?P"> 是固定的，所以兩個人都扣掉 <img src="https://latex.codecogs.com/png.latex?P/2"> 後，即為零和賽局。</p>
</section>
<section id="求詐唬頻率" class="level3">
<h3 class="anchored" data-anchor-id="求詐唬頻率">求詐唬頻率</h3>
<p>理解了賽局的框架，現在我們回到剛剛的例子，來求解 B 的最佳詐唬頻率 <img src="https://latex.codecogs.com/png.latex?%5Cbeta">，和 A 的最佳跟注頻率 <img src="https://latex.codecogs.com/png.latex?%5Calpha">。</p>
<p><strong>B 的最佳進攻策略:</strong></p>
<p>假設 A 選擇了一個 <img src="https://latex.codecogs.com/png.latex?%5Calpha">，輪到 B，這時 B 要選擇一個 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 來最大化自己的期望值。我們使用 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:E_for_beta%7D">，這是一個關於 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 的線性函數: <img src="https://latex.codecogs.com/png.latex?%0Ag(%5Cbeta)%20=%20C%20+%20%5Cbeta%20%5Ccdot%20M%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?M%20=%20%5Cfrac%7B4%7D%7B5%7D%20%5Cleft(%20-%5Calpha%20(B+P)%20+%20P%20%5Cright)">。</p>
<ul>
<li>如果 <img src="https://latex.codecogs.com/png.latex?M%20%3E%200">，B (想要最大化自己的收益) 就會選擇 <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%201"> (Always Bluff)。</li>
<li>如果 <img src="https://latex.codecogs.com/png.latex?M%20%3C%200">，B 就會選擇 <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%200"> (Never Bluff)。</li>
<li>如果 <img src="https://latex.codecogs.com/png.latex?M%20=%200">，B 對於 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 的選擇是無所謂的。</li>
</ul>
<p>把 <img src="https://latex.codecogs.com/png.latex?M"> 再換回 <img src="https://latex.codecogs.com/png.latex?%5Calpha">： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbeta%20=%20%5Cbeta(%5Calpha)%20=%0A%5Cbegin%7Bcases%7D%0A1,%20&amp;%20%5Ctext%7Bif%20%7D%20%5Calpha%20%3C%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20%5C%5C%0A0,%20&amp;%20%5Ctext%7Bif%20%7D%20%5Calpha%20%3E%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20%5C%5C%0A%5Ctext%7Bany%20value%20in%20%7D%20%5B0,1%5D,%20&amp;%20%5Ctext%7Bif%20%7D%20%5Calpha%20=%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20%5C%5C%0A%5Cend%7Bcases%7D%0A"></p>
<p>回想剪刀石頭布的例子，也就是 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 太小時，B 可以一律詐唬來剝削 A；<img src="https://latex.codecogs.com/png.latex?%5Calpha"> 太大時，B 就永遠不詐唬來避免被剝削。但在 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20%5Cfrac%7BP%7D%7BP%20+%20B%7D"> 時。</p>
<p>直覺上這個「讓 B 怎麼選都無所謂」的點，就是 A 的最佳防守。但我們還是先代回去 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:E_for_beta%7D"> 看看 <img src="https://latex.codecogs.com/png.latex?%0A%5Cmax_%7B%5Cbeta%7D%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B)%20=%20%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft(%20%5Calpha%20B%20+%20P%20%5Cright)%20+%20%5Cmax%20%5Cleft(0,%20%5Cfrac%7B4%7D%7B5%7D%20%5Cleft(%20-%5Calpha%20(B+P)%20+%20P%20%5Cright)%20%20%5Cright)%0A"> 這是兩段折線組成的函數，轉折點在 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20%5Cfrac%7BP%7D%7BP%20+%20B%7D">。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmax_%7B%5Cbeta%7D%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B)%0A&amp;=%0A%5Cbegin%7Bcases%7D%0A%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft(%20%5Calpha%20B%20+%20P%20%5Cright)%20+%20%5Cfrac%7B4%7D%7B5%7D%20%5Cleft(%20-%5Calpha%20(B+P)%20+%20P%20%5Cright),%20&amp;%20%5Ctext%7Bif%20%7D%20%5Calpha%20%3C%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20%5C%5C%0A%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft(%20%5Calpha%20B%20+%20P%20%5Cright),%20&amp;%20%5Ctext%7Bif%20%7D%20%5Calpha%20%5Cge%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20%5C%5C%0A%5Cend%7Bcases%7D%20%5C%5C%0A&amp;=%20%5Cbegin%7Bcases%7D%0AP%20-%20%5Calpha%20%5Cfrac%7B3B+4P%7D%7B5%7D,%20&amp;%20%5Ctext%7Bif%20%7D%20%5Calpha%20%3C%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20%5C%5C%0A%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft(%20%5Calpha%20B%20+%20P%20%5Cright),%20%20&amp;%20%5Ctext%7Bif%20%7D%20%5Calpha%20%5Cge%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20%5C%5C%20%20%0A%5Cend%7Bcases%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>這個公式的意思是，若 B 針對 A 的策略 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 做出最佳回應 (也就是 <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%20%5Cbeta(%5Calpha)"> 會隨著 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 而改變)，將 B 的 Payoff 期望值看成是 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 的函數。</p>
<p>這下輪到 A 選擇。 A 要選一個 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 來最小化 B 的期望值。</p>
<p>可以看出，折線的前半段是遞減的，後半段是遞增的，所以最小值會出現在轉折點 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20%5Cfrac%7BP%7D%7BP%20+%20B%7D">。</p>
<p>而最小值為： <img src="https://latex.codecogs.com/png.latex?%0A%5Cmin_%7B%5Calpha%7D%20%5Cmax_%7B%5Cbeta%7D%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B)%20=%20%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft(%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20B%20+%20P%20%5Cright)%0A"> 這是這個遊戲的 Value。對 B 而言是正的，代表 B 有利可圖。</p>
<p><strong>A 的最佳進攻策略:</strong></p>
<p>完全同樣的論述，可以解出 A 的最佳進攻策略。</p>
<p>來快速看一下，這時就用到 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:E_for_alpha%7D">，這是一個關於 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 的線性函數。</p>
<p>如果 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 太小，A 就會選擇 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%201"> (Always Call)；如果 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 太大，A 就會選擇 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%200"> (Always Fold)。 <img src="https://latex.codecogs.com/png.latex?%0A%5Calpha%20=%20%5Calpha(%5Cbeta)%20=%0A%5Cbegin%7Bcases%7D%0A1,%20&amp;%20%5Ctext%7Bif%20%7D%20%5Cbeta%20%3C%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5C%5C%0A0,%20&amp;%20%5Ctext%7Bif%20%7D%20%5Cbeta%20%3E%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5C%5C%0A%5Ctext%7Bany%20value%20in%20%7D%20%5B0,1%5D,%20&amp;%20%5Ctext%7Bif%20%7D%20%5Cbeta%20=%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5C%5C%20%20%0A%5Cend%7Bcases%7D%0A"> 代回去看看: <img src="https://latex.codecogs.com/png.latex?%0A%5Cmin_%7B%5Calpha%7D%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B)%20=%20%5Cfrac%7B1%7D%7B5%7D%20P%20%5Cleft(%201%20+%204%5Cbeta%20%5Cright)%20+%20%5Cmin%20%5Cleft(0,%20%5Cfrac%7BB%7D%7B5%7D%20-%20%5Cfrac%7B4%7D%7B5%7D%20%5Cbeta%20(B%20+%20P)%20%5Cright)%0A"> 這也是兩段折線組成的函數，轉折點在 <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D">。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmin_%7B%5Calpha%7D%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B)%0A&amp;=%0A%5Cbegin%7Bcases%7D%0A%5Cfrac%7B1%7D%7B5%7D%20P%20%5Cleft(%201%20+%204%5Cbeta%20%5Cright),%20&amp;%20%5Ctext%7Bif%20%7D%20%5Cbeta%20%3C%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5C%5C%0A%5Cfrac%7B1%7D%7B5%7D%20P%20%5Cleft(%201%20+%204%5Cbeta%20%5Cright)%20+%20%5Cleft(%20%5Cfrac%7BB%7D%7B5%7D%20-%20%5Cfrac%7B4%7D%7B5%7D%20%5Cbeta%20(B%20+%20P)%20%5Cright),%20&amp;%20%5Ctext%7Bif%20%7D%20%5Cbeta%20%5Cge%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5C%5C%0A%5Cend%7Bcases%7D%20%5C%5C%0A&amp;=%20%5Cbegin%7Bcases%7D%0A%5Cfrac%7B1%7D%7B5%7D%20P%20%5Cleft(%201%20+%204%5Cbeta%20%5Cright),%20&amp;%20%5Ctext%7Bif%20%7D%20%5Cbeta%20%3C%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5C%5C%0A%5Cfrac%7B1%7D%7B5%7D%20(P%20+%20B)%20-%20%5Cfrac%7B4P%7D%7B5%7D%20%5Cbeta,%20%20&amp;%20%5Ctext%7Bif%20%7D%20%5Cbeta%20%5Cge%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5C%5C%20%20%0A%5Cend%7Bcases%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 現在要找 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 來最大化這個函數。因為前半段是遞增的，後半段是遞減的，所以最大值會出現在轉折點 <img src="https://latex.codecogs.com/png.latex?%5Cbeta%20=%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D">。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cmax_%7B%5Cbeta%7D%20%5Cmin_%7B%5Calpha%7D%20%5Cmathbb%7BE%7D(%5Ctext%7BPayoff%7D_B)%20=%20%5Cfrac%7B1%7D%7B5%7D%20P%20%5Cleft(%201%20+%204%20%5Ccdot%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5Cright)%20=%20%5Cfrac%7B1%7D%7B5%7D%20%5Ccdot%20%5Cleft(%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20B%20+%20P%20%5Cright)%0A"> 這結果跟剛剛一樣，代表我們找到了納許均衡點。同時，我們也手動驗證了 Min-Max 定理在這個賽局中成立。</p>
<p><strong>結論</strong></p>
<p>由此得出，納許均衡點為: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Calpha%5E*%20&amp;=%20%5Cfrac%7BP%7D%7BP%20+%20B%7D%20%5C%5C%0A%5Cbeta%5E*%20&amp;=%20%5Cfrac%7BB%7D%7B4(P%20+%20B)%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>這個結論可以細品一下: 如果 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 固定選在 <img src="https://latex.codecogs.com/png.latex?%5Calpha%5E*"> 上，B 怎麼選 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 都無所謂；如果 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 固定選在 <img src="https://latex.codecogs.com/png.latex?%5Cbeta%5E*"> 上，A 怎麼選 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 都無所謂。</p>
<p>但是若有一方偏離這個點，則另一方就可以透過極端策略來進行剝削。但同時也暴露出自己的弱點。</p>
<p>這個架構跟剪刀石頭布是幾乎一樣的。</p>
</section>
<section id="速算法-無異原理-indifference-principle" class="level3">
<h3 class="anchored" data-anchor-id="速算法-無異原理-indifference-principle">速算法: 無異原理 (Indifference Principle)</h3>
<p>費了很大一番功夫，我們終於確認納許均衡點。但每次都要列出落落長的全機率公式再微分實在太慢了。</p>
<p>我們剛才發現一個關鍵性質：「若 A 取 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20%5Cfrac%7BP%7D%7BP%20+%20B%7D"> 時，則 B 對於 <img src="https://latex.codecogs.com/png.latex?%5Cbeta"> 的選擇是無所謂的（期望值相同）。」</p>
<p>這其實就是微積分中「極值點斜率為零」的賽局版本。既然 B 在均衡點時，對於「詐唬」或「不詐唬」的期望值應該一樣（否則他就會全部倒向其中一邊），我們可以直接針對 <strong>B 的決策節點 (Decision Node)</strong> 列式。</p>
<p><strong>怎麼心算 A 的最佳跟注率 (<img src="https://latex.codecogs.com/png.latex?%5Calpha">)?</strong></p>
<p>我們要讓 B 在「拿到爛牌」時，對於 <strong>Check</strong> 和 <strong>Bluff</strong> 感到無差別。 (注意：我們不需要考慮 B 拿到好牌的情況，因為那裡他一定會下注，沒有決策難題)。</p>
<ol type="1">
<li><strong>若 B 選擇 Check (放棄):</strong> 他直接輸掉，收益為 <img src="https://latex.codecogs.com/png.latex?0">。</li>
<li><strong>若 B 選擇 Bluff (下注 <img src="https://latex.codecogs.com/png.latex?B">):</strong>
<ul>
<li>有 <img src="https://latex.codecogs.com/png.latex?(1-%5Calpha)"> 的機率 A 蓋牌，B 贏得底池 <img src="https://latex.codecogs.com/png.latex?P">。</li>
<li>有 <img src="https://latex.codecogs.com/png.latex?%5Calpha"> 的機率 A 跟注，B 被抓包，輸掉賭注 <img src="https://latex.codecogs.com/png.latex?B">。</li>
</ul></li>
</ol>
<p>令兩者期望值相等： <img src="https://latex.codecogs.com/png.latex?0%20=%20(1-%5Calpha)%20%5Ccdot%20P%20+%20%5Calpha%20%5Ccdot%20(-B)"></p>
<p>一眼就能看出這就是著名的 <strong>Pot Odds</strong> 公式變體： <img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Ccdot%20B%20=%20(1-%5Calpha)%20%5Ccdot%20P%20%5Cimplies%20%5Calpha%20=%20%5Cfrac%7BP%7D%7BP+B%7D"></p>
<p>這告訴我們一個很反直覺的真理： <strong>A 的最佳防守頻率 (<img src="https://latex.codecogs.com/png.latex?%5Calpha">)，完全取決於底池賠率，跟 B 到底有多少機率拿到同花毫無關係！</strong></p>
<hr>
<p><strong>怎麼心算 B 的最佳詐唬率 (<img src="https://latex.codecogs.com/png.latex?%5Cbeta">)?</strong></p>
<p>我們要讓 A 在面對下注時，對於 <strong>Call (跟注)</strong> 和 <strong>Fold (蓋牌)</strong> 感到無差別。</p>
<ol type="1">
<li><p><strong>若 A 選擇 Fold:</strong> 收益為 <img src="https://latex.codecogs.com/png.latex?0"> (不賠不賺，底池送給 B)。</p></li>
<li><p><strong>若 A 選擇 Call:</strong> 這時候 A 贏或輸，取決於 B 到底是真的有牌 (Value Bet) 還是偷雞 (Bluff)。</p>
<ul>
<li><strong>A 贏 (B 詐唬):</strong> 贏得底池 <img src="https://latex.codecogs.com/png.latex?P"> 加上 B 的下注 <img src="https://latex.codecogs.com/png.latex?B">。</li>
<li><strong>A 輸 (B 有同花):</strong> 輸掉跟注金額 <img src="https://latex.codecogs.com/png.latex?B">。</li>
</ul></li>
</ol>
<p>為了讓 A 無差別 (EV of Call = 0)，<strong>A 贏的獲利期望值</strong> 必須等於 <strong>A 輸的風險期望值</strong>。</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BProb(Bluff)%7D%20%5Ctimes%20(P%20+%20B)%20=%20%5Ctext%7BProb(Value)%7D%20%5Ctimes%20B%0A"></p>
<p>移項整理一下，這就是著名的 <strong>賠率平衡公式 (bluff-to-value ratio)</strong>：</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Ctext%7BProb(Bluff)%7D%7D%7B%5Ctext%7BProb(Value)%7D%7D%20=%20%5Cfrac%7BB%7D%7BP%20+%20B%7D%0A"></p>
<p>這告訴我們：B 的 <strong>詐唬頻率</strong> 對比 <strong>價值注頻率</strong>，必須剛好等於 <strong>A 的跟注賠率 (Pot Odds)</strong>。</p>
<p>現在把題目中的機率帶進去： * <strong>Prob(Value):</strong> B 拿到同花且下注。機率是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B5%7D%20%5Ctimes%201"> (有牌必打)。 * <strong>Prob(Bluff):</strong> B 沒拿到同花且下注。機率是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B4%7D%7B5%7D%20%5Ctimes%20%5Cbeta"> (沒牌詐唬)。</p>
<p>代回公式： <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cfrac%7B4%7D%7B5%7D%5Cbeta%7D%7B%5Cfrac%7B1%7D%7B5%7D%7D%20=%20%5Cfrac%7BB%7D%7BP+B%7D%0A"></p>
<p>左邊消掉 5： <img src="https://latex.codecogs.com/png.latex?%0A4%5Cbeta%20=%20%5Cfrac%7BB%7D%7BP+B%7D%0A"></p>
<p>解得： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbeta%20=%20%5Cfrac%7B1%7D%7B4%7D%20%5Ccdot%20%5Cfrac%7BB%7D%7BP+B%7D%0A"></p>
<p>這結果跟我們之前用微積分算出來的一模一樣！</p>
<p><strong>[Optional] 註記:</strong></p>
<p>這裡看上去好像真的只要解平衡點就好了，而且 A 的 抓詐唬頻率真的真 B 的反敗為勝機率毫無關係 (在公式上)。</p>
<p>但我們想像一種情況，假設 B 反敗為勝的機率變得超高 (比方說 4/5)，而且池底相對小，比方說 <img src="https://latex.codecogs.com/png.latex?P%20=%2080"> 元，<img src="https://latex.codecogs.com/png.latex?B%20=%2080"> 元。那其實 A 的最佳跟注率並非 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%20%5Cfrac%7B80%7D%7B80+80%7D%20=%200.5">，而是 0 。這也很符合直覺，因為高機率會輸。這可以用上面代回去論證的方法看出來: 原本是 前半段函數斜率是負的，後半段是正的，但現在兩段都是正的，所以 A 的最佳策略是 <img src="https://latex.codecogs.com/png.latex?%5Calpha%20=%200">。</p>
<p>不過這種情況在實際的撲克中很少見，因為在這種設定下(只有B知道自己是否獲勝)，反敗為勝的機率通常不會太高，也就是池底大部分的牌都可以讓 B 組出好牌。這違反了撲克的常識。</p>


</section>
</section>

 ]]></description>
  <category>Poker</category>
  <guid>https://your-website-url.example.com/posts/poker/lesson_4_bluff_value_ratio.html</guid>
  <pubDate>Thu, 04 Dec 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>一天證明一個 Normal Distribution 的性質 Day9： Poisson Summation Formula</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/normal-distribution/day_9.html</link>
  <description><![CDATA[ 



<p>小時候就學過無窮等比級數:</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20r%5En%20=%20%5Cfrac%7B1%7D%7B1-r%7D,%20%5Cquad%20%7Cr%7C%3C1%0A"> 當時候胡思亂想，想說指數部分如果改成平方怎麼算? <img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20r%5E%7Bn%5E2%7D%20=%20?%0A"> 嗯… 當然是完全不會算，沒想到在大學的殿堂裡還會再次遇見他… <strong>Poisson Summation Formula (PSF)</strong>。</p>
<p>這真的是數學中最奇怪又深奧的恆等式。</p>
<section id="柏松求和公式---高斯函數" class="level3">
<h3 class="anchored" data-anchor-id="柏松求和公式---高斯函數">柏松求和公式 - 高斯函數</h3>
<p>柏松求和公式 (Poisson Summation Formula) 告訴我們，如果上面那個函數叫做 <img src="https://latex.codecogs.com/png.latex?S(t)">: <img src="https://latex.codecogs.com/png.latex?%0AS(t)%20:=%20%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-%5Cpi%20t%20n%5E2%7D%20%20%5Cqquad%20%5Cforall%20t%20%3E%200%0A"> 對於所有 <img src="https://latex.codecogs.com/png.latex?t%3E0"> 都有定義，這裡我們稍微未卜先知，做了一個變數變換 <img src="https://latex.codecogs.com/png.latex?r=e%5E%7B-%5Cpi%20t%7D">，不過這是等價的。</p>
<p>那麼我們可以把它寫成另一個無窮級數: <img src="https://latex.codecogs.com/png.latex?%0AS(t)%20=%20%5Cfrac%7B1%7D%7B%5Csqrt%7Bt%7D%7D%20%5Csum_%7Bk=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-%5Cfrac%7B%5Cpi%20k%5E2%7D%7Bt%7D%7D%20=%20%5Cfrac%7B1%7D%7B%5Csqrt%7Bt%7D%7D%20S%5Cleft(%5Cfrac%7B1%7D%7Bt%7D%5Cright)%0A%5Ctag%7B1%7D%5Clabel%7Beq:psf_s%7D%0A"> 疑，形式還是 <img src="https://latex.codecogs.com/png.latex?S"> 但是 input <img src="https://latex.codecogs.com/png.latex?t"> 變成了倒數 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7Bt%7D">。前面還乘以 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B%5Csqrt%7Bt%7D%7D">。</p>
<p>你說，這樣有了 <img src="https://latex.codecogs.com/png.latex?S(t)"> 跟 <img src="https://latex.codecogs.com/png.latex?S(%5Cfrac%7B1%7D%7Bt%7D)"> 的關係，我們還是沒辦法算出來啊？對！但這個對稱性本身，暗示了一個更宏大的幾何結構。</p>
</section>
<section id="jacobi-theta-function-與神秘的空間-m-optional" class="level3">
<h3 class="anchored" data-anchor-id="jacobi-theta-function-與神秘的空間-m-optional">Jacobi Theta Function 與神秘的空間 M [Optional]</h3>
<p>當一個函數滿足一個 functional equation (函數方程式) 的時候，這時候我們就要來研究是否有唯一解? 若不唯一，那解有哪些?</p>
<p>我們很自然地可以將 <img src="https://latex.codecogs.com/png.latex?S(t)"> 定義到複數平面 (只要實部大於 0)。 這樣我們就可以把 <img src="https://latex.codecogs.com/png.latex?S(t)"> 視為一個所謂的 <strong>Jacobi Theta Function</strong>: <img src="https://latex.codecogs.com/png.latex?%0A%5Ctheta(z;%20%5Ctau)%20:=%20%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B%5Cpi%20i%20%5Ctau%20n%5E2%7D%20e%5E%7B2%20%5Cpi%20i%20n%20z%7D%0A"> 這邊 <img src="https://latex.codecogs.com/png.latex?z%20%5Cin%20%5Cmathbb%7BC%7D">，<img src="https://latex.codecogs.com/png.latex?%5Ctau%20%5Cin%20%5Cmathbb%7BH%7D"> (上半平面，對應原本的 <img src="https://latex.codecogs.com/png.latex?it">)。因為 <img src="https://latex.codecogs.com/png.latex?n%5E2"> 跑得比 <img src="https://latex.codecogs.com/png.latex?n"> 快，所以我們只需要 <img src="https://latex.codecogs.com/png.latex?%5Ctau"> 的虛部大於 0 就可以保證收斂性。</p>
<p>常見的 theta function 總共有四種，我們這邊用到的是 <img src="https://latex.codecogs.com/png.latex?%5Ctheta_3">（當 <img src="https://latex.codecogs.com/png.latex?z=0"> 時就是我們原本的級數）。</p>
<p>這時候，讓我們退一步看。剛剛那個 <img src="https://latex.codecogs.com/png.latex?S(t)%20=%20%5Cfrac%7B1%7D%7B%5Csqrt%7Bt%7D%7DS(1/t)"> 的性質，用複數語言寫出來，其實是在說這個函數在經過特定的「變換」（比如 <img src="https://latex.codecogs.com/png.latex?%5Ctau%20%5Cto%20-1/%5Ctau">）後，會變回自己乘以一個因子。</p>
<p>那我們能不能用將這個等式推廣到複數函數 <img src="https://latex.codecogs.com/png.latex?%5Ctheta(0;%20%5Ctau)"> 上呢？ 可以的! 經過一些複雜的分析技巧，我們可以得到: <img src="https://latex.codecogs.com/png.latex?%0A%5Ctheta(0;%20%5Cfrac%7B-1%7D%7B%5Ctau%7D)%20=%20%5Csqrt%7B%5Cfrac%7B%5Ctau%7D%7Bi%7D%7D%20%5C,%20%5Ctheta(0;%20%5Ctau)%0A"></p>
<p>這類具有高度對稱性的函數，居住在一個叫做 <strong>模形式 (Modular Forms)</strong> 的向量空間 <img src="https://latex.codecogs.com/png.latex?M"> 裡。</p>
<p>簡單來說，如果一個函數 <img src="https://latex.codecogs.com/png.latex?f"> 滿足： <img src="https://latex.codecogs.com/png.latex?%0Af%5Cleft(%5Cfrac%7Ba%5Ctau+b%7D%7Bc%5Ctau+d%7D%5Cright)%20=%20(c%5Ctau+d)%5Ek%20f(%5Ctau)%20%20%20%0A%5Cqquad%20,%20%5Cforall%20%5Cbegin%7Bpmatrix%7D%20a%20&amp;%20b%20%5C%5C%20c%20&amp;%20d%20%5Cend%7Bpmatrix%7D%20%5Cin%20SL(2,%20%5Cmathbb%7BZ%7D),%20%5Cforall%20%5Ctau%20%5Cin%20%5Cmathbb%7BH%7D%0A"> 我們就說它是權重為 <img src="https://latex.codecogs.com/png.latex?k"> 的模形式。我們的 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 函數大致上就是這樣的一個東西（權重 <img src="https://latex.codecogs.com/png.latex?k=1/2">）。</p>
<blockquote class="blockquote">
<p><strong>這個空間 <img src="https://latex.codecogs.com/png.latex?M"> 是有限維的！</strong></p>
<p>在某些特定的限制條件下(例如 <img src="https://latex.codecogs.com/png.latex?k=12">)，這個空間的維度甚至只有 <strong>1</strong>。這意味著什麼？這意味著如果我們在這個空間裡找到了兩個函數，它們極有可能是同一個東西（或是只差一個常數倍）。這也就是為什麼數論學家能用 Theta Function 解決很多整數拆分問題的原因——因為路只有一條。</p>
</blockquote>
<p>這邊有點含糊了，因為當 <img src="https://latex.codecogs.com/png.latex?k=1/2"> 根號複數 <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7Bc%5Ctau+d%7D"> 會有選分支的問題。所以其實權重 <img src="https://latex.codecogs.com/png.latex?k=1/2"> 的模形式要退縮到一個較小的子群，通常是 Level 4 的同餘子群 <img src="https://latex.codecogs.com/png.latex?%5CGamma_0(4)">。而在空間 <img src="https://latex.codecogs.com/png.latex?M_%7B1/2%7D(%5CGamma_0(4))"> 中，其維度為 1。</p>
<p>這以後有機會再深入講解。</p>
</section>
<section id="離散高斯" class="level3">
<h3 class="anchored" data-anchor-id="離散高斯">離散高斯</h3>
<p>且讓我們看著 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 的定義式，是不是長得有點像特徵函數 (Characteristic Function) 呢？</p>
<p>讓我們回憶一下機率論。對於一個連續的高斯分佈 (Normal Distribution)，其機率密度函數 (PDF) 是 <img src="https://latex.codecogs.com/png.latex?e%5E%7B-x%5E2%7D"> 的形式，而它的特徵函數 (Characteristic Function, Fourier Transform of PDF) 算出來依然是 <img src="https://latex.codecogs.com/png.latex?e%5E%7B-%5Cxi%5E2%7D"> 的形式。</p>
<p>那如果是<strong>離散</strong>的呢？</p>
<p>假設我們有一個隨機變數 <img src="https://latex.codecogs.com/png.latex?X">，它只能取整數值 <img src="https://latex.codecogs.com/png.latex?n%20%5Cin%20%5Cmathbb%7BZ%7D">，而且取 <img src="https://latex.codecogs.com/png.latex?n"> 的機率正比於高斯分佈: <img src="https://latex.codecogs.com/png.latex?%0AP(X=n)%20%5Cpropto%20e%5E%7B-%5Cpi%20t%20n%5E2%7D%0A"> 這就是一個 <strong>Discrete Gaussian</strong>。</p>
<p>那麼這個離散變數的特徵函數 (Characteristic Function) 是什麼？定義是 <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5Be%5E%7Bi%20%5Comega%20X%7D%5D">： <img src="https://latex.codecogs.com/png.latex?%0A%5Cphi_X(%5Comega)%20=%20%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20P(X=n)%20e%5E%7Bi%20n%20%5Comega%7D%20%5Cpropto%20%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-%5Cpi%20t%20n%5E2%7D%20e%5E%7Bi%20n%20%5Comega%7D%0A"> <strong>確實就是 <img src="https://latex.codecogs.com/png.latex?%5Ctheta_3(z;%20%5Ctau)"> 阿!</strong> (只要令 <img src="https://latex.codecogs.com/png.latex?%5Comega%20=%202%5Cpi%20z">, <img src="https://latex.codecogs.com/png.latex?%5Ctau%20=%20-i%20t">)</p>
<p>所以，我們可以這樣理解：</p>
<ol type="1">
<li><strong>連續世界</strong>：高斯函數的傅立葉變換是高斯函數。</li>
<li><strong>離散世界</strong>：Theta Function 其實就是「離散高斯分佈」的特徵函數。</li>
</ol>
<p>不過這邊是成正比，分母還差了一個 <img src="https://latex.codecogs.com/png.latex?%5Ctheta_3(0;%20it)">，這是為了讓機率加總為 1。</p>
<hr>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/normal-distribution/images/psf.png" class="img-fluid figure-img"></p>
<figcaption class="figure-caption">Poisson Summation Formula</figcaption>
</figure>
</div>
</section>
<section id="附錄poisson-summation-formula-psf-的證明" class="level3">
<h3 class="anchored" data-anchor-id="附錄poisson-summation-formula-psf-的證明">附錄：Poisson Summation Formula (PSF) 的證明</h3>
<p>雖然前面講得很玄，但數學還是要回歸嚴謹。為什麼 <img src="https://latex.codecogs.com/png.latex?%5Csum%20f(n)"> 會等於 <img src="https://latex.codecogs.com/png.latex?%5Csum%20%5Chat%7Bf%7D(k)">？這裡給出一個完整的證明。</p>
<p><strong>定理敘述:</strong> 假設 <img src="https://latex.codecogs.com/png.latex?f(x)%20%5Cin%20L%5E1(%5Cmathbb%7BR%7D)"> 是一個連續函數，且滿足足夠的衰減條件（見證明）。定義其傅立葉變換為 <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bf%7D(%5Cxi)%20=%20%5Cint_%7B-%5Cinfty%7D%5E%5Cinfty%20f(x)e%5E%7B-2%5Cpi%20i%5Cxi%20x%7Ddx">。則： <img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f(n)%20=%20%5Csum_%7Bk=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Chat%7Bf%7D(k)%0A"></p>
<p><strong>證明：</strong></p>
<p>我們引入一個輔助函數，將 <img src="https://latex.codecogs.com/png.latex?f(x)"> 進行「週期化 (Periodization)」，假設級數收斂： <img src="https://latex.codecogs.com/png.latex?%0AF(x)%20:=%20%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f(x+n)%0A"></p>
<p><strong>第一步：確認 <img src="https://latex.codecogs.com/png.latex?F(x)"> 的性質</strong></p>
<p>顯然 <img src="https://latex.codecogs.com/png.latex?F(x)"> 是一個週期為 1 的函數。</p>
<p>既然是週期函數，我們就可以將其展開為 <strong>傅立葉級數 (Fourier Series)</strong>： <img src="https://latex.codecogs.com/png.latex?%0AF(x)%20=%20%5Csum_%7Bk=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20c_k%20e%5E%7B2%5Cpi%20i%20k%20x%7D%0A"> 其中係數 <img src="https://latex.codecogs.com/png.latex?c_k"> 的計算公式為： <img src="https://latex.codecogs.com/png.latex?%0Ac_k%20=%20%5Cint_%7B0%7D%5E%7B1%7D%20F(x)%20e%5E%7B-2%5Cpi%20i%20k%20x%7D%20dx%0A"></p>
<p><strong>第二步：連結 <img src="https://latex.codecogs.com/png.latex?c_k"> 與 <img src="https://latex.codecogs.com/png.latex?%5Chat%7Bf%7D"> (關鍵步驟)</strong></p>
<p>將 <img src="https://latex.codecogs.com/png.latex?F(x)"> 的定義代入 <img src="https://latex.codecogs.com/png.latex?c_k">： <img src="https://latex.codecogs.com/png.latex?%0Ac_k%20=%20%5Cint_%7B0%7D%5E%7B1%7D%20%5Cleft(%20%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f(x+n)%20%5Cright)%20e%5E%7B-2%5Cpi%20i%20k%20x%7D%20dx%0A"></p>
<p>這裡我們遇到了一個數學上的危險操作：<strong>積分與求和交換 (Interchange of Summation and Integration)</strong>。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cint_%7B0%7D%5E%7B1%7D%20%5Csum_%7Bn%7D%20(...)%20%5Cstackrel%7B?%7D%7B=%7D%20%5Csum_%7Bn%7D%20%5Cint_%7B0%7D%5E%7B1%7D%20(...)%0A"> <strong>交換的條件：</strong> 根據 Fubini 定理或控制收斂定理 (Dominated Convergence Theorem)，我們需要 <img src="https://latex.codecogs.com/png.latex?f(x)"> 衰減得夠快。一個充分條件是存在常數 <img src="https://latex.codecogs.com/png.latex?C%3E0"> 與 <img src="https://latex.codecogs.com/png.latex?%5Cdelta%20%3E%200">，使得： <img src="https://latex.codecogs.com/png.latex?%0A%7Cf(x)%7C%20%5Cle%20%5Cfrac%7BC%7D%7B(1+%7Cx%7C)%5E%7B1+%5Cdelta%7D%7D%0A"> 這保證了 <img src="https://latex.codecogs.com/png.latex?%5Csum%20%7Cf(x+n)%7C"> 是一致收斂的，積分與求和便可交換。</p>
<p>交換後： <img src="https://latex.codecogs.com/png.latex?%0Ac_k%20=%20%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Cint_%7B0%7D%5E%7B1%7D%20f(x+n)%20e%5E%7B-2%5Cpi%20i%20k%20x%7D%20dx%0A"> 利用 <img src="https://latex.codecogs.com/png.latex?e%5E%7B-2%5Cpi%20i%20k%20x%7D"> 的週期性， <img src="https://latex.codecogs.com/png.latex?e%5E%7B-2%5Cpi%20i%20k%20x%7D%20=%20e%5E%7B-2%5Cpi%20i%20k%20(x+n)%7D">，我們可以把積分變數變換 <img src="https://latex.codecogs.com/png.latex?y%20=%20x+n">： <img src="https://latex.codecogs.com/png.latex?%0Ac_k%20=%20%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Cint_%7Bn%7D%5E%7Bn+1%7D%20f(y)%20e%5E%7B-2%5Cpi%20i%20k%20y%7D%20dy%0A"> 觀察這個式子，這是把實數軸切成一段一段長度為 1 的區間，然後全部加起來。根據積分的可加性，這等於從 <img src="https://latex.codecogs.com/png.latex?-%5Cinfty"> 積到 <img src="https://latex.codecogs.com/png.latex?%5Cinfty">： <img src="https://latex.codecogs.com/png.latex?%0Ac_k%20=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f(y)%20e%5E%7B-2%5Cpi%20i%20k%20y%7D%20dy%20=%20%5Chat%7Bf%7D(k)%0A"></p>
<p><strong>第三步：代回並取值</strong></p>
<p>現在我們知道 <img src="https://latex.codecogs.com/png.latex?F(x)%20=%20%5Csum_%7Bk%7D%20%5Chat%7Bf%7D(k)%20e%5E%7B2%5Cpi%20i%20k%20x%7D">。</p>
<p>令 <img src="https://latex.codecogs.com/png.latex?x=0">，我們得到： <img src="https://latex.codecogs.com/png.latex?%0AF(0)%20=%20%5Csum_%7Bk=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Chat%7Bf%7D(k)%0A"> 回顧 <img src="https://latex.codecogs.com/png.latex?F(x)"> 的原始定義 <img src="https://latex.codecogs.com/png.latex?F(0)%20=%20%5Csum_%7Bn%7D%20f(n)">，兩式合併即得證： <img src="https://latex.codecogs.com/png.latex?%0A%5Csum_%7Bn=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f(n)%20=%20%5Csum_%7Bk=-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Chat%7Bf%7D(k)%0A"></p>
<p>Q.E.D.</p>


</section>

 ]]></description>
  <category>Normal Distribution</category>
  <guid>https://your-website-url.example.com/posts/normal-distribution/day_9.html</guid>
  <pubDate>Sat, 29 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>一天證明一個 Normal Distribution 的性質 Day8： C n 取 k</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/normal-distribution/day_8.html</link>
  <description><![CDATA[ 




<p>「從 52 張撲克牌中，隨機抽 7 張牌，有多少種不同的組合方式？」</p>
<p>「<img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cbinom%7B52%7D%7B7%7D">，嗯… 可能要按一下計算機?」</p>
<p>「不用，我們可以利用常態分佈的近似來心算看看！」</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbinom%7B52%7D%7B7%7D%20=%20%5Cfrac%7B52%5Ctimes%2051%20%5Ctimes%2050%20%5Ctimes%2049%20%5Ctimes%2048%20%5Ctimes%2047%20%5Ctimes%2046%7D%7B7%20%5Ctimes%206%20%5Ctimes%205%20%5Ctimes%204%20%5Ctimes%203%20%5Ctimes%202%20%5Ctimes%201%7D%0A"></p>
<section id="常態分佈近似" class="level3">
<h3 class="anchored" data-anchor-id="常態分佈近似">常態分佈近似?</h3>
<p>我們要用機率的觀點，計算 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B2%5E%7B52%7D%7D%5Cbinom%7B52%7D%7B7%7D">。也就是擲 <img src="https://latex.codecogs.com/png.latex?52"> 枚公正的硬幣，有多少機率會出現 <img src="https://latex.codecogs.com/png.latex?7"> 個正面朝上？</p>
<ul>
<li>平均值: <img src="https://latex.codecogs.com/png.latex?Np%20=%2052%20%5Ctimes%20%5Cfrac%7B1%7D%7B2%7D%20=%2026"></li>
<li>變異數: <img src="https://latex.codecogs.com/png.latex?Np(1-p)%20=%2052%20%5Ctimes%20%5Cfrac%7B1%7D%7B2%7D%20%5Ctimes%20%5Cfrac%7B1%7D%7B2%7D%20=%2013"></li>
<li>標準差: <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7BNp(1-p)%7D%20=%20%5Csqrt%7B13%7D%20%5Capprox%203.6"></li>
</ul>
<p>所以有正面朝上的個數分布大約就是： <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(26,%203.6%5E2)">。</p>
<p>但因為常態分佈是描述連續的機率密度，而我們擲硬幣是離散的。</p>
<p>所以應該是要算：從 <img src="https://latex.codecogs.com/png.latex?6.5"> 到 <img src="https://latex.codecogs.com/png.latex?7.5"> 的區間下的常態分佈面積，但也可以用 <img src="https://latex.codecogs.com/png.latex?x=7"> 那個點的機率密度來近似(想成用寬度為1的長方形近似)。</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0Af(z)%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%5Csigma%5E2%7D%7D%20e%5E%7B-%5Cfrac%7B(z-%5Cmu)%5E2%7D%7B2%5Csigma%5E2%7D%7D%0A=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%5Ctimes%2013%7D%7D%20e%5E%7B-%5Cfrac%7B(7-26)%5E2%7D%7B2%20%5Ctimes%2013%7D%7D%0A=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B26%5Cpi%7D%7D%20e%5E%7B-%5Cfrac%7B361%7D%7B26%7D%7D%20%20%5C%5C%0A&amp;%5Capprox%20%5Cfrac%7B1%7D%7B%5Csqrt%7B80%7D%7D%20%5Ctimes%20e%5E%7B-14%7D%0A%5Cend%7Baligned%7D%0A"> 記得還要乘上 <img src="https://latex.codecogs.com/png.latex?2%5E%7B52%7D"> 才是組合數。</p>
<p>這邊需要一些常用的近似值：</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?2%5E%7B10%7D%20%5Capprox%2010%5E3"></li>
<li><img src="https://latex.codecogs.com/png.latex?e%5E3%20%5Capprox%2020"></li>
<li><img src="https://latex.codecogs.com/png.latex?e%5E7%20%5Capprox%201100"></li>
</ul>
<p>所以估計 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbinom%7B52%7D%7B7%7D%0A%5Capprox%202%5E%7B52%7D%20%5Ctimes%20%5Cfrac%7B1%7D%7B%5Csqrt%7B80%7D%7D%20%5Ctimes%20e%5E%7B-14%7D%0A%5Capprox%20%5Cfrac%7B4%20%5Ctimes%2010%5E%7B15%7D%7D%7B9%20%5Ctimes%2010%5E6%20%5Ctimes%201.1%5E2%7D%0A%5Capprox%204%20%5Ctimes%2010%5E8%0A"></p>
<p>實際上 <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B52%7D%7B7%7D%20=%20133784560">，我們的估計值大約是 <img src="https://latex.codecogs.com/png.latex?3"> 倍左右! <strong>意外地不準! 為什麼?</strong></p>
</section>
<section id="梯形近似" class="level3">
<h3 class="anchored" data-anchor-id="梯形近似">梯形近似</h3>
<p>其實以心算來說已經夠了，如果再算更複雜還不如用電腦算。 但我們實在很想知道，這個不準的來源，是來自於哪裡?</p>
<ol type="1">
<li>常態分佈 <img src="https://latex.codecogs.com/png.latex?%5Capprox"> 二項分佈。</li>
<li>用長方形(寬度 1) 近似曲線底下的面積。</li>
</ol>
<p>我們來算算看梯形面積會不會好一點? <em>(P.S 這裡已經失去了速算的意義，單純研究誤差來源)</em></p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cfrac%7Bf(6.5)+f(7.5)%7D%7B2%7D%0A&amp;=%20%5Cfrac%7B1%7D%7B2%7D%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%5Ctimes%2013%7D%7D%20%5Cleft(%20e%5E%7B-%5Cfrac%7B(6.5-26)%5E2%7D%7B2%20%5Ctimes%2013%7D%7D%20+%20e%5E%7B-%5Cfrac%7B(7.5-26)%5E2%7D%7B2%20%5Ctimes%2013%7D%7D%20%5Cright)%20%5C%5C%0A&amp;%5Capprox%20%5Cfrac%7B1%7D%7B2%5Ctimes%209%7D%20%5Cleft(%20e%5E%7B-14.625%7D%20+%20e%5E%7B-13.1%7D%20%5Cright)%20%5C%5C%0A&amp;%5Capprox%20%5Cfrac%7B1%7D%7B18%7D%20%5Cleft(%20%5Cfrac%7B1%7D%7B2.2%20%5Ctimes%2010%5E6%7D%20+%20%5Cfrac%7B1%7D%7B5%20%5Ctimes%2010%5E5%7D%20%5Cright)%0A%5Capprox%20%5Cfrac%7B1%7D%7B18%7D%20%5Ctimes%20%5Cfrac%7B1.22%7D%7B5%20%5Ctimes%2010%5E5%7D%0A%5Capprox%20%5Cfrac%7B1%7D%7B7.4%20%5Ctimes%2010%5E6%7D%0A%5Cend%7Baligned%7D%0A"> 剛才是約 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B9%20%5Ctimes%2010%5E6%7D">，已經是高估三倍了，這次是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B7.4%20%5Ctimes%2010%5E6%7D">，誤差又更大了!!</p>
<p>因為 convexity 的關係，在超過 <img src="https://latex.codecogs.com/png.latex?%5Cmu%20%5Cpm%20%5Csigma">後，常態分佈曲線已經是『下凸』 (Convex / Concave Up，像碗一樣向上彎)，梯形面積反而比長方形面積誤差還更大，所以誤差更大了。當然可以用切線近似之類的，但本質上最大問題，在於常態分佈本身在離 <img src="https://latex.codecogs.com/png.latex?%5Cmu"> 很遠的地方，已經無法很好近似二項分佈了。</p>
<p>(P.S. 雖然說常態分佈的尾巴比二項分布還要厚，但是已經比其他真實世界的分佈還薄很多，例如股市漲跌幅、或是Student-t分布。)</p>
</section>
<section id="大偏差理論-large-deviation-theory" class="level3">
<h3 class="anchored" data-anchor-id="大偏差理論-large-deviation-theory">大偏差理論 Large Deviation Theory</h3>
<p>我們花了一番力氣證明，無論是用長方形還是梯形去近似常態分佈下的面積，都無法修復 3 倍以上的誤差。這意味著：<strong>問題不在於積分技巧，而在於模型本身。</strong></p>
<p>這個現象在機率論裡有一個專門的學科在研究，叫做 大偏差理論 (Large Deviation Theory, LDT)。</p>
<p>我們擲 52 次硬幣，平均正面次數 <img src="https://latex.codecogs.com/png.latex?%5Cmu=26">。但我們卻想計算 <img src="https://latex.codecogs.com/png.latex?k=7"> 的機率。</p>
<p><img src="https://latex.codecogs.com/png.latex?k=7"> 是一個<strong>極端事件 (Extreme Event)</strong>。雖然常態分佈是根據中央極限定理（Central Limit Theorem, CLT）得出的，它保證了當 <img src="https://latex.codecogs.com/png.latex?n"> 夠大時，中央區域的表現很像常態分佈。但是，CLT 並不保證尾部的行為。</p>
<p>LDT 研究的正是這些極端事件發生的機率是如何指數級地衰減。它告訴我們，當事件離平均值越遠，常態分佈的近似（它假設了 <img src="https://latex.codecogs.com/png.latex?e%5E%7B-x%5E2%7D"> 的衰減）就會嚴重失真。對於 <img src="https://latex.codecogs.com/png.latex?z%20%5Capprox%20-5.3"> 這種極端偏差，我們必須使用更精確的工具。</p>
<blockquote class="blockquote">
<p>根據 大偏差理論 (Large Deviation Theory) 中的 Cramér’s Theorem，對於樣本平均數 <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BX%7D_n"> 偏離期望值 <img src="https://latex.codecogs.com/png.latex?p"> 的機率，其衰減速度並不是常態分佈描述的 <img src="https://latex.codecogs.com/png.latex?e%5E%7B-x%5E2%7D">，而是由 速率函數 (Rate Function) <img src="https://latex.codecogs.com/png.latex?I(x)"> 決定的： <img src="https://latex.codecogs.com/png.latex?%0AP(%5Cbar%7BX%7D_n%20%5Capprox%20x)%20%5Capprox%20e%5E%7B-n%20I(x)%7D%0A"> 對於伯努利分佈（投硬幣），這個速率函數 <img src="https://latex.codecogs.com/png.latex?I(x)"> 其實就是 相對熵 (KL Divergence)： <img src="https://latex.codecogs.com/png.latex?%0AI(x)%20=%20x%20%5Cln%20%5Cfrac%7Bx%7D%7Bp%7D%20+%20(1-x)%20%5Cln%20%5Cfrac%7B1-x%7D%7B1-p%7D%0A"> 在我們的例子中，<img src="https://latex.codecogs.com/png.latex?n=52,%20p=0.5,%20x=7/52">。如果我們計算 <img src="https://latex.codecogs.com/png.latex?e%5E%7B-n%20I(x)%7D">，你會發現它剛好等於我們後面要用的那個「神奇修正項」： <img src="https://latex.codecogs.com/png.latex?%0Ae%5E%7B-52%20%5Ccdot%20I(7/52)%7D%20=%20%5Cleft(%5Cfrac%7B7/52%7D%7B1/2%7D%5Cright)%5E%7B-7%7D%20%5Cleft(%5Cfrac%7B45/52%7D%7B1/2%7D%5Cright)%5E%7B-45%7D%20%5Ctimes%20(%5Ctext%7B%E5%B8%B8%E6%95%B8%7D)%0A"> 也就是說，LDT 準確預測了常態分佈在尾部會失效，並且告訴我們失效的幅度（修正項）剛好就是相對熵的指數！為了具體計算這個值，我們可以使用 LDT 常用的技巧：<strong>指數傾斜 (Exponential Tilting)</strong>，也就是把機率測度變換到讓事件變成「中心」的地方!</p>
</blockquote>
<p>既然在原本的機率分佈 (<img src="https://latex.codecogs.com/png.latex?p=0.5">) 下， <img src="https://latex.codecogs.com/png.latex?k=7"> 是個看不清楚的邊緣地帶，那我們不如創造一個新的平行宇宙，在這個宇宙裡，<img src="https://latex.codecogs.com/png.latex?k=7"> 才是最正常的事件。</p>
<p>我們可以定義一個新的二項分佈，讓它的參數變成 <img src="https://latex.codecogs.com/png.latex?p'=%5Cfrac%7B7%7D%7B52%7D">，這樣我們就可以把 <img src="https://latex.codecogs.com/png.latex?k=7"> 這個事件，轉換成在新分佈下的「平均事件」。</p>
<p>在新的分布下，</p>
<ul>
<li>平均值 <img src="https://latex.codecogs.com/png.latex?%5Cmu'%20=%20Np%20=%2052%20%5Ctimes%20%5Cfrac%7B7%7D%7B52%7D%20=%207">，</li>
<li>變異數 <img src="https://latex.codecogs.com/png.latex?%5Csigma'%5E2%20=%20Np(1-p)%20=%2052%20%5Ctimes%20%5Cfrac%7B7%7D%7B52%7D%20%5Ctimes%20%5Cleft(1%20-%20%5Cfrac%7B7%7D%7B52%7D%5Cright)%20=%207%20%5Ctimes%20%5Cfrac%7B45%7D%7B52%7D%20%5Capprox%206.06">，</li>
</ul>
<p><img src="https://latex.codecogs.com/png.latex?%0AP'(X=7)%20=%20%5Cbinom%7B52%7D%7B7%7D%20(p')%5E7%20(1-p')%5E%7B45%7D%0A"></p>
<p>根據我們的常態分佈近似（因為現在 7 是平均值，也就是峰值，近似會非常準確）： <img src="https://latex.codecogs.com/png.latex?%0AP'(X=7)%20%5Capprox%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%20%5Csigma'%5E2%7D%7D%0A"></p>
<p>將兩式合併，我們就可以反推組合數 <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B52%7D%7B7%7D">： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cbinom%7B52%7D%7B7%7D%0A&amp;%5Capprox%20%5Cfrac%7B1%7D%7B%5Cleft(%5Cfrac%7B7%7D%7B52%7D%5Cright)%5E7%20%5Cleft(%5Cfrac%7B45%7D%7B52%7D%5Cright)%5E%7B45%7D%7D%20%5Ctimes%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%20%5Ctimes%2052%20%5Cfrac%7B7%7D%7B52%7D%20%5Cfrac%7B45%7D%7B52%7D%20%7D%7D%20%5C%5C%0A&amp;%5Capprox%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20%5Cfrac%7B52%5E%7B52%7D%7D%7B7%5E7%20%5Ctimes%2045%5E%7B45%7D%7D%20%5Ctimes%20%5Cfrac%7B%5Csqrt%7B52%7D%7D%7B%5Csqrt%7B7%5Ctimes%2045%7D%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20%5Cfrac%7B%5Csqrt%7B52%7D%7D%7B%5Csqrt%7B7%5Ctimes%2045%7D%7D%20e%5E%7B52%20H(%5Cfrac%7B7%7D%7B52%7D)%7D%0A%5Cend%7Baligned%7D%0A"></p>
<p>這正是 Stirling Formula 的形式！ 我們繞了一大圈，利用機率觀點的「換底操作」，重新發現了階乘近似公式。雖然這完全失去了心算的意義，但這揭示了常態分佈、大偏差理論與組合數學之間深刻的連結。</p>
<p>作為收尾，我們比較一下這跟剛才 <img src="https://latex.codecogs.com/png.latex?p=1/2"> 時的近似值： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cbinom%7B52%7D%7B7%7D%0A&amp;%5Capprox%202%5EN%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%5Csigma%5E2%7D%7D%20e%5E%7B-%5Cfrac%7B(k-%5Cfrac%7BN%7D%7B2%7D)%5E2%7D%7B2%20%5Csigma%5E2%7D%7D%20%5Cqquad%5Ctext%7B%20,%20where%20%7D%20%5Csigma%5E2=%5Cfrac%7BN%7D%7B4%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20%5Cfrac%7B1%7D%7B%5Csqrt%7B%5Cfrac%7BN%7D%7B4%7D%7D%7D%20e%5E%7BN%5Cln(2)%20-%20%5Cfrac%7B(k-%5Cfrac%7BN%7D%7B2%7D)%5E2%7D%7B%5Cfrac%7BN%7D%7B2%7D%7D%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20%5Cfrac%7B2%7D%7B%5Csqrt%7BN%7D%7D%20e%5E%7BN%20%5Cleft%5B%20%5Cln(2)%20-%202%5Cleft(%5Cfrac%7B1%7D%7B2%7D%20-%20%5Cfrac%7Bk%7D%7BN%7D%5Cright)%5E2%20%5Cright%5D%20%7D%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>假設我們不看係數的誤差，令 <img src="https://latex.codecogs.com/png.latex?x=%5Cfrac%7Bk%7D%7BN%7D">，比較兩個指數部分的差異，正確的是用 <img src="https://latex.codecogs.com/png.latex?H(x)">，而錯誤近似的是用 <img src="https://latex.codecogs.com/png.latex?%5Cln(2)%20-%202%5Cleft(%5Cfrac%7B1%7D%7B2%7D%20-%20x%5Cright)%5E2">，是一個二次函數的近似。</p>
<p>這樣就看得很清楚了，當 <img src="https://latex.codecogs.com/png.latex?x=1/2"> 兩者相等，但當 <img src="https://latex.codecogs.com/png.latex?x"> 遠離 <img src="https://latex.codecogs.com/png.latex?1/2"> 時，二次函數的近似會越來越高估 <img src="https://latex.codecogs.com/png.latex?H(x)"> 的值，導致組合數被高估。</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/normal-distribution/images/image.png" class="img-fluid figure-img"></p>
<figcaption>Figure 1: <img src="https://latex.codecogs.com/png.latex?H(x)"> vs <img src="https://latex.codecogs.com/png.latex?%5Cln(2)%20-%202%5Cleft(%5Cfrac%7B1%7D%7B2%7D%20-%20x%5Cright)%5E2"></figcaption>
</figure>
</div>


</section>

 ]]></description>
  <category>Normal Distribution</category>
  <guid>https://your-website-url.example.com/posts/normal-distribution/day_8.html</guid>
  <pubDate>Fri, 28 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>Poker Lesson 3 - hands 組合數</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/poker/lesson_3_count.html</link>
  <description><![CDATA[ 




<p>今天我們來算一下 同花順、四條、葫蘆、同花、順子、三條、兩對、一對、散牌 在撲克中出現的機率。</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="https://your-website-url.example.com/posts/poker/images/poker_cardprob_57.png" class="img-fluid figure-img"></p>
<figcaption>Poker Counts Takeaway</figcaption>
</figure>
</div>
<p><strong>同花順 (straight flush) 的方法數:</strong> 在一副標準的 52 張撲克牌中，有 4 種花色，每種花色有 13 張牌。同花順是指五張連續數字且同花色的牌。首先，我們可以有 10 種不同的同花順組合（A-5, 2-6, …, 10-A）。 每種花色有 1 種組合，所以同花順的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A4%20%5Ctimes%2010%20=%2040%0A"></p>
<p><strong>四條 (four of a kind) 的方法數:</strong> 要組成四條，我們需要從 13 個數字中選擇 1 個數字來組成四張牌，然後從剩下的 12 個數字中選擇 1 個數字來組成單張牌。每個數字的四張牌有 <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B4%7D%7B4%7D%20=%201"> 種組合，而單張牌有 4 種組合。所以四條的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A13%20%5Ctimes%201%20%5Ctimes%2012%20%5Ctimes%204%20=%20624%0A"></p>
<p><strong>葫蘆 (full house) 的方法數:</strong> 葫蘆是指三張同數字的牌加上兩張同數字的牌。首先，我們從 13 個數字中選擇一個數字來組成三張牌，然後從剩下的 12 個數字中選擇一個數字來組成兩張牌。每個數字的三張牌有 <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B4%7D%7B3%7D%20=%204"> 種組合，而兩張牌有 <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B4%7D%7B2%7D%20=%206"> 種組合。所以葫蘆的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A13%20%5Ctimes%204%20%5Ctimes%2012%20%5Ctimes%206%20=%203744%0A"></p>
<p><strong>同花 (flush) 的方法數:</strong> 要組成同花，我們需要從同一花色中選出 5 張牌。但要扣掉同花順。所以，同花的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A4%20%5Ctimes%20%5Cbinom%7B13%7D%7B5%7D%20-%2040%20=%204%20%5Ctimes%201287%20-%2040%20=%205108%0A"></p>
<p><strong>順子 (straight) 的方法數:</strong> 順子是指五張連續數字的牌，不考慮花色。在 13 個數字中（A, 2, 3, …, 10, J, Q, K），我們可以有 10 種不同的順子組合（A-5, 2-6, …, 10-A）。每張牌可以有 4 種花色，一樣要扣掉同花順。所以順子的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A10%20%5Ctimes%204%5E5%20-%2040%20=%2010%20%5Ctimes%201024%20-%2040%20=%2010200%0A"></p>
<p><strong>三條 (three of a kind) 的方法數:</strong> 要組成三條，我們需要從 13 個數字中選擇 1 個數字來組成三張牌，然後從剩下的 12 個數字中選擇 2 個數字來組成單張牌。每個數字的三張牌有 <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B4%7D%7B3%7D%20=%204"> 種組合，而單張牌有 4 種組合。所以三條的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A13%20%5Ctimes%204%20%5Ctimes%20%5Cbinom%7B12%7D%7B2%7D%20%5Ctimes%204%5E2%20=%2013%20%5Ctimes%204%20%5Ctimes%2066%20%5Ctimes%2016%20=%2054912%0A"></p>
<p><strong>兩對 (two pairs) 的方法數:</strong> 要組成兩對，我們需要從 13 個數字中選擇 2 個數字來組成兩對，然後從剩下的 11 個數字中選擇 1 個數字來組成單張牌。每個數字的兩張牌有 <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B4%7D%7B2%7D%20=%206"> 種組合，而單張牌有 4 種組合。所以兩對的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbinom%7B13%7D%7B2%7D%20%5Ctimes%206%5E2%20%5Ctimes%2011%20%5Ctimes%204%20=%2078%20%5Ctimes%2036%20%5Ctimes%2044%20=%20123552%0A"></p>
<p><strong>一對 (one pair) 的方法數:</strong> 要組成一對，我們需要從 13 個數字中選擇 1 個數字來組成一對，然後從剩下的 12 個數字中選擇 3 個數字來組成單張牌。每個數字的兩張牌有 <img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B4%7D%7B2%7D%20=%206"> 種組合，而單張牌有 4 種組合。所以一對的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A13%20%5Ctimes%206%20%5Ctimes%20%5Cbinom%7B12%7D%7B3%7D%20%5Ctimes%204%5E3%20=%2013%20%5Ctimes%206%20%5Ctimes%20220%20%5Ctimes%2064%20=%201098240%0A"></p>
<p><strong>散牌 (high card) 的方法數:</strong> 散牌是指沒有任何組合的牌。我們需要從 13 個數字中選擇 5 個數字來組成散牌，然後從每個數字中選擇 1 張牌。每張牌有 4 種組合。但是要扣掉可能是順子和同花的組合數量。所以散牌的組合數量為： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbinom%7B13%7D%7B5%7D%20%5Ctimes%204%5E5%20-%2010200%20-%205108%20-%2040%20=%201287%20%5Ctimes%201024%20-%2010200%20-%205108%20-%2040%20=%201302540%0A"></p>
<p>檢查一下所有手牌組合數量的總和是否等於 52 張牌中選 5 張的總組合數： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbinom%7B52%7D%7B5%7D%20=%202598960%0A"></p>
<p>而各手牌組合數量總和為： <img src="https://latex.codecogs.com/png.latex?%0A40%20+%20624%20+%203744%20+%205108%20+%2010200%20+%2054912%20+%20123552%20+%201098240%20+%201302540%20=%202598960%0A"> 符合預期!</p>
<p><strong>直方圖:</strong></p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="93" data-source-offset="-14" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 92;"><span id="cb1-93">Plotly <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="pp" style="color: #AD0000;
background-color: null;
font-style: inherit;">require</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"https://cdn.plot.ly/plotly-2.27.0.min.js"</span>)</span>
<span id="cb1-94"></span>
<span id="cb1-95"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 定義手牌類型及其組合數量</span></span>
<span id="cb1-96">handTypes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb1-97">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Full House"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3744</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-98">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flush"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5148</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-99">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Straight"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10240</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-100">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Three of a Kind"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">54912</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-101">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Two Pairs"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">123552</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-102">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One Pair"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1098240</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-103">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High Card"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1302540</span> }</span>
<span id="cb1-104">]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-105"></span>
<span id="cb1-106"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 繪製直方圖</span></span>
<span id="cb1-107">{</span>
<span id="cb1-108">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> DOM<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'div'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-109">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> totalCombos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2598960</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-110">  Plotly<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">newPlot</span>(div<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [{</span>
<span id="cb1-111">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bar'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-112">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> handTypes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-113">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> handTypes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> totalCombos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-114">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marker</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#69b3a2'</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-115">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> handTypes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> totalCombos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">%`</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-116">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textposition</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'auto'</span></span>
<span id="cb1-117">  }]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb1-118">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">yaxis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb1-119">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Probability (%)'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-120">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'log'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-121">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">gridcolor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#e5e5e5'</span></span>
<span id="cb1-122">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-123">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">xaxis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb1-124">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Hand Type'</span></span>
<span id="cb1-125">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-126">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">margin</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">b</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">l</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-127">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">plot_bgcolor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#ffffff'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-128">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">paper_bgcolor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#ffffff'</span></span>
<span id="cb1-129">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb1-130">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">staticPlot</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">true</span></span>
<span id="cb1-131">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-132">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> div<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-133">}</span></code></pre></div></div>
<div id="fig-poker-hand-counts" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-poker-hand-counts-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<div id="fig-poker-hand-counts-1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-poker-hand-counts-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-poker-hand-counts-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-poker-hand-counts-2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-poker-hand-counts-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-poker-hand-counts-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-poker-hand-counts-3" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-poker-hand-counts-3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-1-3" data-nodetype="expression">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-poker-hand-counts-3-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(c)
</figcaption>
</figure>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-poker-hand-counts-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: 撲克手牌組合數量直方圖
</figcaption>
</figure>
</div>
</div>
<section id="texas-holdem" class="level3">
<h3 class="anchored" data-anchor-id="texas-holdem">Texas Hold’em</h3>
<p>但在德州撲克中，假設跟到第五張，我們是從七張牌中選五張來組成最好的手牌。所以我們可以計算從七張牌中組成各種手牌的組合數量。</p>
<p>首先，我們必須確立樣本空間的總數。在德州撲克中，玩家最終會有 7 張牌（2 張手牌 + 5 張公牌），我們需要從這 52 張牌中選出 7 張，總組合數為：</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbinom%7B52%7D%7B7%7D%20=%20133,784,560%0A"> 這個數字比 5 張牌的 260 萬大了約 50 倍，計算過程中會出現許多「重疊」的情況（例如手上有 6 張同花色的牌，或者同時擁有兩對和三條），我們必須確保只計算該手牌能組成的<strong>最佳</strong>牌型。</p>
<p><strong>同花順 (Straight Flush) 的方法數:</strong> 這包含了皇家同花順。在 7 張牌中要湊出同花順，意味著這 7 張牌中至少包含了 5 張連續且同花色的牌。 這需要考慮 7 張牌剛好構成 5 張、6 張或 7 張連續同花的情況。經過排容原理計算後，共有： <img src="https://latex.codecogs.com/png.latex?41,584%20">機率約為 <img src="https://latex.codecogs.com/png.latex?0.03%5C%25">。</p>
<p><strong>四條 (Four of a Kind) 的方法數:</strong> 這比較好算。我們需要從 13 個數字選 1 個做為四條（<img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B13%7D%7B1%7D">），這四張牌全拿（<img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B4%7D%7B4%7D">）。剩下的 3 張牌可以從剩餘的 48 張牌中任意選擇（<img src="https://latex.codecogs.com/png.latex?%5Cbinom%7B48%7D%7B3%7D">）。 注意：即便剩下的 3 張牌湊成一對甚至三條，因為四條是大牌，最佳手牌依然是四條，所以不用扣除。 <img src="https://latex.codecogs.com/png.latex?%0A13%20%5Ctimes%201%20%5Ctimes%20%5Cbinom%7B48%7D%7B3%7D%20=%2013%20%5Ctimes%2017,296%20=%20224,848%0A"></p>
<p><strong>葫蘆 (Full House) 的方法數:</strong> 這是 7 張牌中最容易算錯的部分。因為在 7 張牌中，你可能拿到「三條+三條」（取大的三條配小的一對算葫蘆）、「三條+兩對」、「三條+一對」。 經過詳細分類計算（此處省略繁瑣的排容過程），總共有： <img src="https://latex.codecogs.com/png.latex?%0A3,473,184%0A"></p>
<p><strong>同花 (Flush) 的方法數:</strong> 我們需要 7 張牌中至少有 5 張同一花色，且不包含同花順。 算法是：選 1 種花色，然後從該花色 13 張選 7 張、選 6 張配 1 張雜牌、或選 5 張配 2 張雜牌。最後減去同花順的數量。 組合數為：</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A4%20%5Ctimes%20%5B%5Cbinom%7B13%7D%7B7%7D%20+%20%5Cbinom%7B13%7D%7B6%7D%5Cbinom%7B39%7D%7B1%7D%20+%20%5Cbinom%7B13%7D%7B5%7D%5Cbinom%7B39%7D%7B2%7D%5D%20-%2041,584%20=%204,047,644%0A"></p>
<p>在德州撲克中，葫蘆機率 <em>依然小於</em> 同花機率，並沒有反轉!</p>
<p>P.S. 在短牌撲克（Short Deck Poker）中，由於去掉了 2-5，共 36 張牌，葫蘆反而變得比同花更容易出現(反轉!)，這是因為牌數減少後，同花的組合數下降幅度較大所致。所以在短牌規則中通常是「同花 &gt; 葫蘆」。</p>
<p><strong>順子 (Straight) 的方法數:</strong> 類似同花，需找出 5、6 或 7 張連續數字，扣除同花順。 總數為： <img src="https://latex.codecogs.com/png.latex?6,180,020%20"></p>
<p><strong>三條 (Three of a Kind) 的方法數:</strong> 指 7 張牌中包含三張同號，但剩下的 4 張牌不能形成另外的三條或一對（否則會變成葫蘆或四條），也不能形成順子或同花。 總數為： <img src="https://latex.codecogs.com/png.latex?%0A6,461,620%0A"></p>
<p><strong>兩對 (Two Pairs) 的方法數:</strong></p>
<p>這在德州撲克中非常常見。你可以拿到 3 對（取最大的兩對），或者 2 對配 3 張散牌。 總數為： <img src="https://latex.codecogs.com/png.latex?31,433,400%20"></p>
<p><strong>一對 (One Pair) 的方法數:</strong> 總數為： <img src="https://latex.codecogs.com/png.latex?58,627,800%20"></p>
<p>這意味著在 Showdown 階段，你有接近 44% 的機率至少持有一對。</p>
<p><strong>散牌 (High Card) 的方法數:</strong> 什麼都沒湊成，連一對都沒有。 總數為： <img src="https://latex.codecogs.com/png.latex?%0A23,294,460%0A"></p>
<p>有趣的是，在 7 張牌選 5 的規則下，<strong>拿散牌的機率比拿一對還要低</strong>（散牌約 17.4%，一對約 43.8%）。這解釋了為什麼在德州撲克中，光靠一張「A High」通常很難贏到底。</p>
<hr>
<p><strong>德州撲克手牌分佈直方圖:</strong></p>
<p>我們將上述 7 選 5 的數據更新到圖表中，你會發現分佈趨勢與標準 5 張牌撲克有所不同，特別是葫蘆與同花的順序對調，以及散牌數量的驟降。</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="212" data-source-offset="-21" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 211;"><span id="cb2-212">texasHandTypes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [</span>
<span id="cb2-213">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// { type: "Straight Flush",  count: 41_584 },</span></span>
<span id="cb2-214">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// { type: "Four of a Kind",  count: 224_848 },</span></span>
<span id="cb2-215">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Full House"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3_473_184</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-216">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Flush"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>           <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4_047_644</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-217">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Straight"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6_180_020</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-218">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Three of a Kind"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6_461_620</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-219">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Two Pairs"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>       <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">31_433_400</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-220">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"One Pair"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">58_627_800</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-221">  { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"High Card"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>       <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">count</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">23_294_460</span> }</span>
<span id="cb2-222">]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-223"></span>
<span id="cb2-224"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 繪製直方圖</span></span>
<span id="cb2-225">{</span>
<span id="cb2-226">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> div <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> DOM<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">element</span>(<span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'div'</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-227">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> totalCombos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">133_784_560</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-228">  Plotly<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">newPlot</span>(div<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> [{</span>
<span id="cb2-229">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'bar'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-230">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> texasHandTypes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">type</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-231">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> texasHandTypes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> (d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> totalCombos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-232">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marker</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'steelblue'</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-233">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> texasHandTypes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>(d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">count</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> totalCombos <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">100</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">%`</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-234">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textposition</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'auto'</span></span>
<span id="cb2-235">  }]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-236">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">yaxis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb2-237">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Probability (%)'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-238">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'log'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-239">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">gridcolor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#e5e5e5'</span></span>
<span id="cb2-240">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-241">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">xaxis</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb2-242">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'Hand Type'</span></span>
<span id="cb2-243">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-244">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">margin</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">t</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">b</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">l</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">80</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">30</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-245">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">plot_bgcolor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#ffffff'</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-246">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">paper_bgcolor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">'#ffffff'</span></span>
<span id="cb2-247">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb2-248">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">staticPlot</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">true</span></span>
<span id="cb2-249">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-250">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> div<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-251">}</span></code></pre></div></div>
<div id="fig-texas-holdem-counts" class="cell quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-texas-holdem-counts-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div class="cell-output cell-output-display">
<div id="fig-texas-holdem-counts-1" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-texas-holdem-counts-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-texas-holdem-counts-1-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(a)
</figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-texas-holdem-counts-2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-subfloat-fig figure">
<div aria-describedby="fig-texas-holdem-counts-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div id="ojs-cell-2-2" data-nodetype="expression">

</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-subfloat-caption quarto-subfloat-fig" id="fig-texas-holdem-counts-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
(b)
</figcaption>
</figure>
</div>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-texas-holdem-counts-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: 德州撲克 (7選5) 手牌組合數量直方圖
</figcaption>
</figure>
</div>
</div>
<hr>
</section>
<section id="總結與洞察" class="level3">
<h3 class="anchored" data-anchor-id="總結與洞察">總結與洞察</h3>
<table class="caption-top table">
<thead>
<tr class="header">
<th>Card Type</th>
<th>5-Card Prob</th>
<th>7-Card Prob</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Four of a Kind</td>
<td>0.0240 %</td>
<td>0.168 %</td>
</tr>
<tr class="even">
<td>Full House</td>
<td>0.1441 %</td>
<td>2.60 %</td>
</tr>
<tr class="odd">
<td>Flush</td>
<td>0.1965 %</td>
<td>3.03 %</td>
</tr>
<tr class="even">
<td>Straight</td>
<td>0.3925 %</td>
<td>4.62 %</td>
</tr>
<tr class="odd">
<td>Three of a Kind</td>
<td>2.1128 %</td>
<td>4.83 %</td>
</tr>
<tr class="even">
<td>Two Pairs</td>
<td>4.7539 %</td>
<td>23.50 %</td>
</tr>
<tr class="odd">
<td>One Pair</td>
<td>42.2569 %</td>
<td>43.82 %</td>
</tr>
<tr class="even">
<td>High Card</td>
<td>50.1177 %</td>
<td>17.41 %</td>
</tr>
</tbody>
</table>
<p>對比 5 張牌與 7 張牌的機率，我們可以得到幾個對實戰有幫助的結論：</p>
<ol type="1">
<li><strong>散牌大幅減少</strong>：在 5 張牌中，散牌佔了 50%；但在 7 張牌中，散牌只佔 17%。這意味著在河牌圈（River），對手大概率是有牌的（至少有一對）。<br>
</li>
<li><strong>高頻手牌</strong>：一對和兩對在 7 張牌中非常常見，分別佔了約 44% 和 23.5%。這表示在實戰中，持有至少一對的機率非常高，這也影響了下注策略和讀牌判斷。</li>
<li><strong>葫蘆與同花機率大幅上升</strong>：從傳統撲克轉到德州撲克，最大的直覺衝擊在於牌型差距的縮小。在傳統撲克中，拿三條比拿葫蘆容易 15 倍，但在德州撲克中，這個差距縮小到了不到 2 倍。這意味著：在德州撲克中，當你拿到三條或順子時，撞上對手拿到同花或葫蘆的機率，比你想像中高得多。我們可以把大牌分成兩組來記：
<ol type="1">
<li>常見強牌組 (約 5%)：三條 與 順子。這兩者出現頻率很高，是底池主要競爭者。</li>
<li>稀有魔王組 (約 3%)：同花 與 葫蘆。雖然只比上面少一點，但在機率上這意味著它們通常能贏過上面的牌。</li>
</ol></li>
</ol>


</section>

 ]]></description>
  <category>Poker</category>
  <guid>https://your-website-url.example.com/posts/poker/lesson_3_count.html</guid>
  <pubDate>Thu, 27 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>Poker Lesson 2 - 一次只能買到一張牌</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/poker/lesson_2.html</link>
  <description><![CDATA[ 




<p>假設 limit Texas Hold’em 中，大小盲注是 30/60，目前翻出三張牌(the flop)，彩池中有 90 元，輪到 Player A 行動。翻牌是 A♥ K♦ 7♥。</p>
<ul>
<li>Player A 手上有 A♠ K♠。</li>
<li>Player B 手上有 J♥ 3♥。</li>
</ul>
<p>現在 Player A bet 60 元，Player B 該如何決定要不要跟注 (call) 呢?</p>
<div id="fig-poker-game-status" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-poker-game-status-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://your-website-url.example.com/posts/poker/images/poker_buyonecard-processed.jpg" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-poker-game-status-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Poker Game
</figcaption>
</figure>
</div>
<hr>
<p>先來算一下彩池賠率 (pot odds)。加上 Player A 的下注，彩池變成 150 元 (90 + 60)，Player B 需要付出 60 元來跟注，所以彩池賠率是 150:60，也就是 2.5:1。</p>
<p>對應到需要的勝率 (required equity)：<img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cfrac%7B1%7D%7B2.5%20+%201%7D%20=%200.2857">，也就是說 Player B 需要有至少 28.57% 的勝率才能跟注。</p>
<p>Player B 目前局勢落後，因為 Player A 是 two-pairs，而 Player B 目前只有 high card J。</p>
<p>但 Player B 只差一張紅心就能組成 flush (同花)。來計算組成紅心的機率。</p>
<p>這邊有個小陷阱，如果是紅心 K，那麼 Player A 就會組成 full house (葫蘆)，比同花更大，所以要扣除紅心 K。</p>
<p>翻牌後還剩下 45 張牌 (52 - 7)，其中有 9 張紅心 (13 - 4)，扣掉紅心 K 後還剩 8 張紅心。所以 Player B 組成 flush 的機率是 <img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cfrac%7B8%7D%7B45%7D%20%5Capprox%2017.78%5C%25">。</p>
<p>這是在第四張牌 (the turn) Player B 就組成 flush 的機率。問題來了，我們該算第四張牌，還是算到第五張牌(the river) 呢? 這勝率 (Equity) 大約多了一倍。</p>
<p>這就牽扯到 Player A 目前的狀況，如果 Player A 已經 all-in，或者判斷在下一輪 Player A 高機率不會再下注。那 Player B 就可以算到第五張牌，直覺上 Player B 用這一個跟注的 call 「買到」看兩張牌的機會。</p>
<p>但一般情況，Player A 很可能在第四張牌後繼續下注，(而且 Player A組成 full house 的機率也不低)。</p>
<p>所以我們來算算看期望值 (EV)：</p>
<ol type="1">
<li>此時彩池有 210 元，其中 60 元是 Player B 即將跟注進去的錢。
<ul>
<li>Player B 在第四張牌就組成 flush 的機率是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B8%7D%7B45%7D">。Player A 之後就不會再加注或跟注。所以假設最好情況，Player B 直接贏得彩池 150 元。(也就是不考慮 Player A 可能組成 full house 翻盤的情況)。這邊的 EV 是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B8%7D%7B45%7D%20%5Ctimes%20150%20%5Capprox%2026.67"> 元。</li>
<li>如果第四張牌讓 Player A 組成 full house (還有兩張 K和兩張 A)，Player B 就直接輸掉這手牌。這機率是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B4%7D%7B45%7D">。這邊的 EV 是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B4%7D%7B45%7D%20%5Ctimes%20(-60)%20%5Capprox%20-5.33"> 元。</li>
<li>如果第四張牌沒讓 Player A 組成 full house，也沒讓 Player B 組成 flush (機率 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B33%7D%7B45%7D">)，比賽繼續，到了第五張牌。</li>
</ul></li>
<li>這時候 Player A 很可能會繼續下注 60 元，Player B 跟注，彩池變成 330 元。其中 120 元是 Player B 跟注進去的錢。
<ul>
<li>Player B 在第五張牌組成 flush 的機率是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B8%7D%7B44%7D">。這邊的 EV 是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B33%7D%7B45%7D%20*%20%5Cfrac%7B8%7D%7B44%7D%20*%20(330%20-%20120)%20=%2028"> 元。</li>
<li>如果第五張牌沒讓 Player B 組成 flush (機率 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B36%7D%7B44%7D">)，Player B 就輸掉這手牌。這邊的 EV 是 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B33%7D%7B45%7D%20%5Ctimes%20%5Cfrac%7B36%7D%7B44%7D%20%5Ctimes%20(-120)%20=%20-72"> 元。</li>
</ul></li>
</ol>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div id="fig-decision-tree" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-decision-tree-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<pre class="mermaid mermaid-js" data-label="fig-decision-tree">graph TD
    %% 定義節點樣式
    R4((The Turn))
    Node2((The River))
    
    %% 定義結構與連接線標籤
    R4 -- "33/45" --&gt; Node2
    R4 -- "4/45" --&gt; A1[A win: -60]
    R4 -- "8/45" --&gt; B1[B win: +150]

    Node2 -- "36/44" --&gt; A2[A win: -120]
    Node2 -- "8/44" --&gt; B2[B win: +210]
    
    %% 樣式調整
    style Node2 fill:#f9fff0, stroke:#333,stroke-width:2px
    style A1 fill:#ffcccc, stroke:#cc0000,stroke-width:2px
    style A2 fill:#ffcccc, stroke:#cc0000,stroke-width:2px
    style B1 fill:#ccffcc, stroke:#00cc00,stroke-width:2px
    style B2 fill:#ccffcc, stroke:#00cc00,stroke-width:2px
</pre>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-decision-tree-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;2: Player A bet 60 on Turn and bet 60 on River
</figcaption>
</figure>
</div>
</div>
</div>
<p>綜合以上情況，Player B 的總 EV 是： <img src="https://latex.codecogs.com/png.latex?%0AEV%20=%2026.67%20-%205.33%20+%2028%20-%2072%20=%20-22.66%0A"> 所以是負的，不建議跟注。</p>
<p>關鍵在最後一個case，也是機率最大的case。若兩輪都沒中 Player B 的flush，從現在看來，損失是 120 元。</p>
<section id="if-player-a-checks-on-the-river" class="level3">
<h3 class="anchored" data-anchor-id="if-player-a-checks-on-the-river">If Player A checks on the River:</h3>
<p>我們可以看一下如果 Player A 在第四張牌後不繼續下注，Player B 輸的話就只損失 60 元，但贏的話可以贏 150 元，這樣 Player B 的 EV 會變成正的。</p>
<div class="cell" data-layout-align="center">
<div class="cell-output-display">
<div id="fig-decision-tree-2" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-decision-tree-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<div>
<pre class="mermaid mermaid-js" data-label="fig-decision-tree-2">graph TD
    %% 定義節點樣式
    R4((The Turn))
    Node2((The River))
    
    %% 定義結構與連接線標籤
    R4 -- "33/45" --&gt; Node2
    R4 -- "4/45" --&gt; A1[A win: -60]
    R4 -- "8/45" --&gt; B1[B win: +150]

    Node2 -- "36/44" --&gt; A2["&lt;b&gt;A win: &lt;span style='color:red'&gt;-60&lt;/span&gt;&lt;/b&gt;"]
    Node2 -- "8/44" --&gt; B2["&lt;b&gt;B win: &lt;span style='color:green'&gt;+150&lt;/span&gt;&lt;/b&gt;"]
    
    %% 樣式調整
    style Node2 fill:#f9fff0, stroke:#333,stroke-width:2px
    style A1 fill:#ffcccc, stroke:#cc0000,stroke-width:2px
    style A2 fill:#ffcccc, stroke:#cc0000,stroke-width:2px
    style B1 fill:#ccffcc, stroke:#00cc00,stroke-width:2px
    style B2 fill:#ccffcc, stroke:#00cc00,stroke-width:2px
</pre>
</div>
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-decision-tree-2-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;3: Player A checks on the River
</figcaption>
</figure>
</div>
</div>
</div>
<p><img src="https://latex.codecogs.com/png.latex?%0AEV%20=%20%5Cfrac%7B8%7D%7B45%7D%20%5Ctimes%20150%20-%20%5Cfrac%7B4%7D%7B45%7D%20%5Ctimes%2060%20+%20%5Cfrac%7B33%7D%7B45%7D%20%5Ctimes%20%5Cleft(%20%5Cfrac%7B8%7D%7B44%7D%20%5Ctimes%20150%20-%20%5Cfrac%7B36%7D%7B44%7D%20%5Ctimes%2060%20%5Cright)%20=%207.27%0A"></p>
</section>
<section id="小結" class="level3">
<h3 class="anchored" data-anchor-id="小結">小結</h3>
<p>回到最一開始，我們計算 Pot Odds 是 2.5:1，對應需要的勝率是 28.57%。 Player B 實際上只有大約 17.78% 的機率在第四張牌就組成 flush，並不足夠跟注。</p>


</section>

 ]]></description>
  <category>Poker</category>
  <guid>https://your-website-url.example.com/posts/poker/lesson_2.html</guid>
  <pubDate>Wed, 26 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>Poker Lesson 1 - 池底賠率 (Pot Odds)</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/poker/lesson_1_pot_odds.html</link>
  <description><![CDATA[ 




<p>先來談談賭博中最小的一步，要 <strong>繼續遊戲 (call)</strong> 還是 <strong>忍痛放棄 (fold)</strong>。</p>
<p>所謂的 Pot Odds，指的是你為了繼續參與遊戲 (call 或 raise) 所需要投入的金額，和你可能贏得的彩池 (pot) 之間的比例。</p>
<p>舉例來說，假設彩池中有 100 美元，而你需要投入 20 美元來繼續參與遊戲，那麼你的 Pot Odds 就是 20:100，或者簡化為 1:5。</p>
<p>那我們該如何判斷是否該繼續參與呢? 假設我們目前評估勝率為 <img src="https://latex.codecogs.com/png.latex?p">，那麼我們可以計算出期望值 (Expected Value, EV)： <img src="https://latex.codecogs.com/png.latex?%0AEV%20=%20p%20%5Ctimes%20%5Ctext%7BPot%20Size%7D%20-%20(1%20-%20p)%20%5Ctimes%20%5Ctext%7BCost%20to%20Call%7D%20%5Ctag%7B1%7D%5Clabel%7Beq:ev-pot-odds%7D%0A"> 若 <img src="https://latex.codecogs.com/png.latex?EV%20%3E%200">，表示長期下來這是一個有利可圖的決策，反之則不然。也就是我們希望 <img src="https://latex.codecogs.com/png.latex?%0Ap%20%3E%20%5Cfrac%7B%5Ctext%7BCost%20to%20Call%7D%7D%7B%5Ctext%7BPot%20Size%7D%20+%20%5Ctext%7BCost%20to%20Call%7D%7D%20%5Ctag%7B2%7D%5Clabel%7Beq:pot-odds-threshold%7D%0A"></p>
<p>在上面例子中，就是 <img src="https://latex.codecogs.com/png.latex?20%20/%20(100%20+%2020)%20=%201/6%20%5Capprox%2016.67%5C%25">。也就是說，如果我們認為自己的勝率超過 16.67%，那麼繼續參與遊戲是有利可圖的。</p>
<div id="fig-poker-pot-odds" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-fig figure">
<div aria-describedby="fig-poker-pot-odds-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<img src="https://your-website-url.example.com/posts/poker/images/poker_potodds_20-processed.png" class="img-fluid figure-img">
</div>
<figcaption class="quarto-float-caption-bottom quarto-float-caption quarto-float-fig" id="fig-poker-pot-odds-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Figure&nbsp;1: Poker Pot Odds
</figcaption>
</figure>
</div>
<section id="odds-vs-probability" class="level3">
<h3 class="anchored" data-anchor-id="odds-vs-probability">Odds vs Probability</h3>
<p>在撲克中，Odds 和 Probability 是兩個相關但不同的概念。 Probability 是指某事件發生的可能性，通常以百分比表示 (例如 25% 的機率)。而 Odds 則是指某事件發生與不發生的比率。</p>
<ul>
<li>1:3 的 Odds 意味著該事件發生的機率是 1/ (1+3) = 25%。</li>
<li>3:1 的 Odds 意味著該事件發生的機率是 3/ (3+1) = 75%。</li>
<li>2:5 的 Odds 意味著該事件發生的機率是 2/ (2+5) ≈ 28.57%。</li>
</ul>


</section>

 ]]></description>
  <category>Poker</category>
  <guid>https://your-website-url.example.com/posts/poker/lesson_1_pot_odds.html</guid>
  <pubDate>Tue, 25 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>一天證明一個 Normal Distribution 的性質 Day7：Hermite Polynomials</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/normal-distribution/day_7.html</link>
  <description><![CDATA[ 



<p>今天回到我們的小數學風格，談點輕鬆的 Hermite Polynomials。</p>
<p>如同其他正交多項式，Hermite polynomial也是一組正交多項式。我們來看一下他的生成函數 (generating function)： <img src="https://latex.codecogs.com/png.latex?%0Ae%5E%7Bxt%20-%20%5Cfrac%7Bt%5E2%7D%7B2%7D%7D%20:=%20%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_n(x)%20%5Cfrac%7Bt%5En%7D%7Bn!%7D%20%20%5Ctag%7B1%7D%5Clabel%7Beq:hermite-generating%7D%0A"></p>
<p>欸，這個生成函數根本就是常態分佈 <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(x,1)"> 的 MGF (moment generating function)！</p>
<p>所以說，第 <img src="https://latex.codecogs.com/png.latex?n"> 階 <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BHe%7D_n(x)"> 的定義其實就是常態分佈 <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(x,1)"> 的 n-th moment 乘上 <img src="https://latex.codecogs.com/png.latex?n!">。</p>
<p>這邊我們用的是 機率學家的埃爾米特多項式 (probabilists’ Hermite polynomials)，另外還有物理學家的 (physicists’ Hermite polynomials)，記做 <img src="https://latex.codecogs.com/png.latex?H_n(x)">，其中 <img src="https://latex.codecogs.com/png.latex?H_n(x)%20=%202%5E%7B%5Cfrac%7Bn%7D%7B2%7D%7D%20%5Ctext%7BHe%7D_n(%5Csqrt%7B2%7Dx)">，也就是在定義上差了兩倍的標準差。本質上是一樣的，所以我們先專注在前者。</p>
<table class="table">
<thead>
<tr class="header">
<th><img src="https://latex.codecogs.com/png.latex?n"></th>
<th>機率學家的 <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BHe%7D_n(x)"></th>
<th>物理學家的 <img src="https://latex.codecogs.com/png.latex?H_n(x)"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>0</td>
<td>1</td>
<td>1</td>
</tr>
<tr class="even">
<td>1</td>
<td><img src="https://latex.codecogs.com/png.latex?x"></td>
<td><img src="https://latex.codecogs.com/png.latex?2x"></td>
</tr>
<tr class="odd">
<td>2</td>
<td><img src="https://latex.codecogs.com/png.latex?x%5E2%20-%201"></td>
<td><img src="https://latex.codecogs.com/png.latex?4x%5E2%20-%202"></td>
</tr>
<tr class="even">
<td>3</td>
<td><img src="https://latex.codecogs.com/png.latex?x%5E3%20-%203x"></td>
<td><img src="https://latex.codecogs.com/png.latex?8x%5E3%20-%2012x"></td>
</tr>
<tr class="odd">
<td>4</td>
<td><img src="https://latex.codecogs.com/png.latex?x%5E4%20-%206x%5E2%20+%203"></td>
<td><img src="https://latex.codecogs.com/png.latex?16x%5E4%20-%2048x%5E2%20+%2012"></td>
</tr>
</tbody>
</table>
<div id="fig-hermite-polynomials" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<div class="sourceCode cell-code hidden" id="cb1" data-startfrom="43" data-source-offset="-45" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 42;"><span id="cb1-43"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">He</span>(n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> x) {</span>
<span id="cb1-44">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-45">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-46">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-47">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-48">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span>x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">**</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-49">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-50">}</span>
<span id="cb1-51"></span>
<span id="cb1-52"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 生成數據點 (-4 到 4)</span></span>
<span id="cb1-53">data <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb1-54">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> points <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-55">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> x <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.05</span>) {</span>
<span id="cb1-56">    [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(n <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb1-57">      points<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>({</span>
<span id="cb1-58">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-59">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">He</span>(n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> x)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-60">        <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">n</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`He</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 分組標籤</span></span>
<span id="cb1-61">      })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-62">    })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-63">  }</span>
<span id="cb1-64">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> points<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb1-65">}</span>
<span id="cb1-66"></span>
<span id="cb1-67"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 繪圖</span></span>
<span id="cb1-68">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb1-69">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// title: "Probabilistic Hermite Polynomials (He0 - He4)",</span></span>
<span id="cb1-70">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-71">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">caption</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">null</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 移除 Observable Plot 的版權標記</span></span>
<span id="cb1-72">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"He_n(x)"</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb1-73">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">color</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> { <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">legend</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">true</span> }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// 自動生成圖例</span></span>
<span id="cb1-74">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb1-75">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span>])<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// X軸基準線</span></span>
<span id="cb1-76">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(data<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {</span>
<span id="cb1-77">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb1-78">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb1-79">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"n"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb1-80">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span> </span>
<span id="cb1-81">    })</span>
<span id="cb1-82">  ]</span>
<span id="cb1-83">})</span></code></pre></div>
<div class="cell-output cell-output-display">
<div id="fig-hermite-polynomials-1" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<div id="ojs-cell-1-1" data-nodetype="declaration">

</div>
<figcaption class="figure-caption">(a) <strong>?(caption)</strong></figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-hermite-polynomials-2" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<div id="ojs-cell-1-2" data-nodetype="declaration">

</div>
<figcaption class="figure-caption">(b) <strong>?(caption)</strong></figcaption>
</figure>
</div>
</div>
<div class="cell-output cell-output-display">
<div id="fig-hermite-polynomials-3" class="quarto-figure quarto-figure-center anchored">
<figure class="figure">
<div id="ojs-cell-1-3" data-nodetype="expression">

</div>
<figcaption class="figure-caption">(c) <strong>?(caption)</strong></figcaption>
</figure>
</div>
</div>
<figcaption class="figure-caption">Figure&nbsp;1: 機率學家的 Hermite 多項式 (He₀ - He₄)</figcaption>
</figure>
</div>
<section id="計算-hermite-多項式" class="level3">
<h3 class="anchored" data-anchor-id="計算-hermite-多項式">計算 Hermite 多項式</h3>
<p><strong>對 <img src="https://latex.codecogs.com/png.latex?x"> 微分:</strong></p>
<p>若將 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hermite-generating%7D"> 兩邊對 <img src="https://latex.codecogs.com/png.latex?x"> 微分，我們可以得到一個遞迴關係式： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cfrac%7B%5Cpartial%7D%7B%5Cpartial%20x%7D%20e%5E%7Bxt%20-%20%5Cfrac%7Bt%5E2%7D%7B2%7D%7D%20=%20t%20e%5E%7Bxt%20-%20%5Cfrac%7Bt%5E2%7D%7B2%7D%7D%20%5C%5C%0A%5Cimplies%20&amp;%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_n'(x)%20%5Cfrac%7Bt%5En%7D%7Bn!%7D%20=%20%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_%7Bn%7D(x)%20%5Cfrac%7Bt%5E%7Bn+1%7D%7D%7Bn!%7D%20=%20%5Csum_%7Bn=1%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_%7Bn-1%7D(x)%20%5Cfrac%7Bt%5E%7Bn%7D%7D%7B(n-1)!%7D%0A%5Cend%7Balign%7D%0A"> 所以我們有： <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BHe%7D_n'(x)%20=%20n%20%5Ctext%7BHe%7D_%7Bn-1%7D(x)%20%5Ctag%7B2%7D%5Clabel%7Beq:hermite-recursion%7D%0A"> 這就足以讓我們依序積分計算出 <img src="https://latex.codecogs.com/png.latex?n"> 階的 Hermite 多項式，但還差常數項。 而常數項 <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BHe%7D_n(0)"> 可以直接從原本的生成函數 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hermite-generating%7D"> 帶入 <img src="https://latex.codecogs.com/png.latex?x=0"> 得到： <img src="https://latex.codecogs.com/png.latex?%0Ae%5E%7B-%5Cfrac%7Bt%5E2%7D%7B2%7D%7D%20=%20%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_n(0)%20%5Cfrac%7Bt%5En%7D%7Bn!%7D%0A"> 注意到左邊其實是偶函數，所以所有奇數階的 Hermite 多項式在 <img src="https://latex.codecogs.com/png.latex?x=0"> 都是 0。 而偶數階的話，我們可以將指數函數展開： <img src="https://latex.codecogs.com/png.latex?%0Ae%5E%7B-%5Cfrac%7Bt%5E2%7D%7B2%7D%7D%20=%20%5Csum_%7Bk=0%7D%5E%7B%5Cinfty%7D%20%5Cfrac%7B(-1)%5Ek%20(t%5E2/2)%5Ek%7D%7Bk!%7D%20=%20%5Csum_%7Bk=0%7D%5E%7B%5Cinfty%7D%20%5Cfrac%7B(-1)%5Ek%20t%5E%7B2k%7D%7D%7B2%5Ek%20k!%7D%0A"> 所以 <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BHe%7D_%7B2k%7D(0)%20=%20%5Cfrac%7B(-1)%5Ek%20(2k)!%7D%7B2%5Ek%20k!%7D,%20%5Cquad%20%5Ctext%7BHe%7D_%7B2k+1%7D(0)%20=%200%20%20%5Ctag%7B3%7D%5Clabel%7Beq:hermite-constant%7D%0A"></p>
<p>但從這個遞迴式實在看不出為什麼 Hermite 多項式一定是整係數。畢竟一直積分是可能會產生分母的。</p>
<p><strong>對 <img src="https://latex.codecogs.com/png.latex?t"> 微分:</strong></p>
<p>應該來試試看對 <img src="https://latex.codecogs.com/png.latex?t"> 微分會得到什麼？</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cfrac%7B%5Cpartial%7D%7B%5Cpartial%20t%7D%20e%5E%7Bxt%20-%20%5Cfrac%7Bt%5E2%7D%7B2%7D%7D%20=%20(x%20-%20t)%20e%5E%7Bxt%20-%20%5Cfrac%7Bt%5E2%7D%7B2%7D%7D%20%20%20%5C%5C%0A%5Cimplies%20&amp;%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_n(x)%20%5Cfrac%7Bt%5E%7Bn-1%7D%7D%7B(n-1)!%7D%20=%20%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%20x%20%5Ctext%7BHe%7D_n(x)%20%5Cfrac%7Bt%5En%7D%7Bn!%7D%20-%20%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_n(x)%20%5Cfrac%7Bt%5E%7Bn+1%7D%7D%7Bn!%7D%20%20%5C%5C%0A%5Cimplies%20&amp;%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_%7Bn+1%7D(x)%20%5Cfrac%7Bt%5E%7Bn%7D%7D%7Bn!%7D%20=%20%5Csum_%7Bn=0%7D%5E%7B%5Cinfty%7D%20%20x%20%5Ctext%7BHe%7D_n(x)%20%5Cfrac%7Bt%5En%7D%7Bn!%7D%20-%20%5Csum_%7Bn=1%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_%7Bn-1%7D(x)%20%5Cfrac%7Bt%5E%7Bn%7D%7D%7B(n-1)!%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 所以我們有另一個遞迴關係式： <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BHe%7D_%7Bn+1%7D(x)%20=%20x%20%5Ctext%7BHe%7D_n(x)%20-%20n%20%5Ctext%7BHe%7D_%7Bn-1%7D(x)%20%5Ctag%7B4%7D%5Clabel%7Beq:hermite-recursion-2%7D%0A"> 我們再用剛才的的遞迴式 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hermite-recursion%7D"> 把 <img src="https://latex.codecogs.com/png.latex?n%5Ctext%7BHe%7D_%7Bn-1%7D(x)"> 換成微分： <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BHe%7D_%7Bn+1%7D(x)%20=%20x%20%5Ctext%7BHe%7D_n(x)%20-%20%5Ctext%7BHe%7D_n'(x)%20=%20%5Cleft(%20x%20-%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%20%5Ctext%7BHe%7D_n(x)%20=%20%5Cleft(%20x%20-%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%5E%7Bn+1%7D%20%5Ccdot%201%20%20%5Ctag%7B5%7D%5Clabel%7Beq:hermite-operator%7D%0A"> 疑? 原本 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hermite-recursion%7D"> 告訴我們要算 <img src="https://latex.codecogs.com/png.latex?n"> 階 Hermite 多項式是一直積分，現在變成了一直乘以 <img src="https://latex.codecogs.com/png.latex?x"> 和微分!</p>
<p>至少我們可以確定，Hermite 多項式的係數一定是整數，因為每一步運算都不會產生分母。</p>
<p>既然是整數，是否可以問他的係數的組合數學的意義? 從 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hermite-operator%7D"> 出發，我們可以展開 <img src="https://latex.codecogs.com/png.latex?(x%20-%20%5Cfrac%7Bd%7D%7Bdx%7D)%5E%7Bn%7D">： <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BHe%7D_n(x)%20=%20%5Csum_%7Bk=0%7D%5E%7Bn%7D%20%5Cbinom%7Bn%7D%7Bk%7D%20x%5E%7Bn-k%7D%20%5Cleft(-%5Cfrac%7Bd%7D%7Bdx%7D%5Cright)%5E%7Bk%7D%20%5Ccdot%201%20=%20%5Csum_%7Bk=0%7D%5E%7Bn%7D%20%5Cbinom%7Bn%7D%7Bk%7D%20x%5E%7Bn-k%7D%20(-1)%5Ek%20%5Cfrac%7Bd%5Ek%7D%7Bdx%5Ek%7D%201%20%20=%20x%5E%7Bn%7D%0A%5Ctag%7BWrong!%7D%0A"> 因為 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Bd%5Ek%7D%7Bdx%5Ek%7D%201%20=%200"> 當 <img src="https://latex.codecogs.com/png.latex?k%20%5Cgeq%201">，所以只有 <img src="https://latex.codecogs.com/png.latex?k=0"> 的項會留下來，這似乎跟我們之前的結論矛盾? 當然不是!! 因為乘以 <img src="https://latex.codecogs.com/png.latex?x"> 和 微分作用是不能交換的，所以不能套用二項式展開式。</p>
<blockquote class="blockquote">
<p><strong>P.S. 組合數意義:</strong></p>
<p><img src="https://latex.codecogs.com/png.latex?%5Ctext%7BHe%7D_n(x)"> 的係數其實對應於 完全圖 (Complete Graph) <img src="https://latex.codecogs.com/png.latex?K_n"> 的匹配數 (Matchings)。 具體來說： <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BHe%7D_n(x)%20=%20%5Csum_%7Bk=0%7D%5E%7B%5Clfloor%20n/2%20%5Crfloor%7D%20(-1)%5Ek%20N(n,%20k)%20x%5E%7Bn-2k%7D%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?N(n,%20k)"> 是 在 <img src="https://latex.codecogs.com/png.latex?n"> 個頂點的完全圖中，選出 <img src="https://latex.codecogs.com/png.latex?k"> 條不相鄰邊 (disjoint edges) 的方法數。</p>
<p><strong>例子 <img src="https://latex.codecogs.com/png.latex?n=4">: <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BHe%7D_4(x)%20=%20x%5E4%20-%206x%5E2%20+%203"></strong></p>
<ul>
<li><p><img src="https://latex.codecogs.com/png.latex?x%5E4"> 項 (<img src="https://latex.codecogs.com/png.latex?k=0">): 選 0 條邊。方法數 = 1。</p></li>
<li><p><img src="https://latex.codecogs.com/png.latex?x%5E2"> 項 (<img src="https://latex.codecogs.com/png.latex?k=1">): 在 4 個點中選 1 條邊。<img src="https://latex.codecogs.com/png.latex?C(4,%202)%20=%206"> 種。</p></li>
<li><p>常數項 (<img src="https://latex.codecogs.com/png.latex?k=2">): 在 4 個點中選 2 條不相鄰的邊 (也就是完美匹配 Perfect Matching) -&gt; 3 種。</p></li>
<li><p>係數正好是 <img src="https://latex.codecogs.com/png.latex?1,%20-6,%203"> (正負號來自公式裡的 <img src="https://latex.codecogs.com/png.latex?(-1)%5Ek">)。這完美的解釋了為什麼係數都是整數！</p></li>
</ul>
</blockquote>
<p><strong>解微分方程:</strong></p>
<p>我們來思考一下這個微分算符，他在物理學上有重要的意義，叫做 創生-消滅算符 (creation-annihilation operator)： <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%20x%20-%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%0A"> 但我們先不談物理意義，之後有機會再補充。如果說要解微分方程: <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%20x%20-%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%20y%20=%20f(x)%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?f(x)"> 是已知。大家以前在大學可能有學過個技巧，叫做 積分因子 (integrating factor)，我們可以試著同乘以一個函數 <img src="https://latex.codecogs.com/png.latex?u(x)"> 來讓左邊變成「一個微分」，而非現在這樣的「乘法減微分」。我這邊不寫通式(因為原理是一樣的)，直接給出結果，取 <img src="https://latex.codecogs.com/png.latex?u(x)%20=%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D">： <img src="https://latex.codecogs.com/png.latex?%0Ae%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Cleft(%20x%20-%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%20y%20=%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20f(x)%0A%5Cimplies%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cleft(%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20y%20%5Cright)%20=%20-%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20f(x)%0A"> 因此就可以寫出通解： <img src="https://latex.codecogs.com/png.latex?%0Ay%20=%20e%5E%7B%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Cleft(%20C%20-%20%5Cint%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20f(x)%20dx%20%5Cright)%0A"></p>
<p>所以說，從算符的角度來看，其實 <img src="https://latex.codecogs.com/png.latex?%0A%5Cleft(%20x%20-%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%20%20=%20e%5E%7B%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Cleft(%20-%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%20%5Ctag%7B6%7D%5Clabel%7Beq:hermite-operator-2%7D%0A"> 因此我們寫出了第三種 Hermite 多項式的定義： <img src="https://latex.codecogs.com/png.latex?%0A%5Ctext%7BHe%7D_n(x)%20=%20e%5E%7B%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Cleft(%20-%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%5E%7Bn%7D%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%20%5Ctag%7B7%7D%5Clabel%7Beq:hermite-definition-3%7D%0A"><br>
其實回到 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hermite-operator-2%7D">，這個等式是一個算符的等式，我們目前只是看到他作用在 1上的特例，而這個轉換不覺得很眼熟嗎? 感覺就像在對矩陣做對角化! 前後乘一個轉換矩陣和它的反矩陣，然後中間是簡單的對角矩陣 (這邊是微分算符)。</p>
</section>
<section id="正交性質" class="level3">
<h3 class="anchored" data-anchor-id="正交性質">正交性質</h3>
<p>在函數空間中，多項式正交就是指內積為零，而內積的定義通常是相乘後在某個權重函數下積分(也可以想成是期望值)。那這組多項式在什麼權重函數下是正交的呢？</p>
<p>我們想選個適當的權重函數 <img src="https://latex.codecogs.com/png.latex?w(x)"> 使得對所有 <img src="https://latex.codecogs.com/png.latex?m%20%5Cneq%20n">： <img src="https://latex.codecogs.com/png.latex?%0A%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_m(x)%20%5Ctext%7BHe%7D_n(x)%20w(x)%20dx%20=%200%0A"> 利用 Hermite 多項式的定義 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hermite-definition-3%7D">，我們有： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_m(x)%20%5Ctext%7BHe%7D_n(x)%20w(x)%20dx%20%5C%5C%0A=&amp;%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Cleft(%20-%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%5E%7Bm%7D%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Ccdot%20%5Ctext%7BHe%7D_n(x)%20w(x)%20dx%20%5C%5C%0A=&amp;%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Cleft(%20-%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%5E%7Bm%7D%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Ccdot%20%5Cleft(%20e%5E%7B%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Ctext%7BHe%7D_n(x)%20w(x)%20%5Cright)%20dx%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 最直覺的想法是讓 <img src="https://latex.codecogs.com/png.latex?w(x)%20=%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D">，這樣就消掉了。然後不斷地做分部積分，直到把 <img src="https://latex.codecogs.com/png.latex?m"> 次微分都移到 <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BHe%7D_n(x)"> 上面： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Cleft(%20-%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%5E%7Bm%7D%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Ccdot%20%5Cleft(%20%5Ctext%7BHe%7D_n(x)%20%5Cright)%20dx%20%5C%5C%0A=&amp;%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20%5Ccdot%20%5Cleft(%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%5E%7Bm%7D%20%5Ctext%7BHe%7D_n(x)%20dx%0A%5Cend%7Balign%7D%0A"> 當 <img src="https://latex.codecogs.com/png.latex?m%20%5Cneq%20n">，我們不妨假設 <img src="https://latex.codecogs.com/png.latex?m%20%3E%20n">，那麼因為 <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BHe%7D_n(x)"> 是 <img src="https://latex.codecogs.com/png.latex?n"> 次多項式，所以經過 <img src="https://latex.codecogs.com/png.latex?m"> 次微分後會變成 0，因此整個積分結果是 0。</p>
<p>若 <img src="https://latex.codecogs.com/png.latex?m=n">，我們可以利用 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:hermite-recursion%7D"> 計算出 <img src="https://latex.codecogs.com/png.latex?%5Cleft(%20%5Cfrac%7Bd%7D%7Bdx%7D%20%5Cright)%5E%7Bn%7D%20%5Ctext%7BHe%7D_n(x)%20=%20n!">，所以整個積分結果是 <img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20n!%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20dx%20=%20n!%20%5Csqrt%7B2%5Cpi%7D">。</p>
<p>因此我們推導出 Hermite 多項式的正交性質： <img src="https://latex.codecogs.com/png.latex?%0A%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Ctext%7BHe%7D_m(x)%20%5Ctext%7BHe%7D_n(x)%20e%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D%20dx%20=%20n!%20%5Csqrt%7B2%5Cpi%7D%20%5Cdelta_%7Bmn%7D%0A%5Ctag%7B8%7D%5Clabel%7Beq:hermite-orthogonality%7D%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?%5Cdelta_%7Bmn%7D"> 是 Kronecker delta。</p>
</section>
<section id="小結" class="level3">
<h3 class="anchored" data-anchor-id="小結">小結</h3>
<p>Hermite 多項式會出現在很多地方，他會是 Fourier Transform 的本徵函數 (eigenfunction)! 敬請期待未來的文章。</p>


</section>

 ]]></description>
  <category>Normal Distribution</category>
  <guid>https://your-website-url.example.com/posts/normal-distribution/day_7.html</guid>
  <pubDate>Mon, 24 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>一天證明一個 Normal Distribution 的性質 Day6：Chi-squared Test</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/normal-distribution/day_6.html</link>
  <description><![CDATA[ 




<section id="chi-squared-test-複習" class="level3">
<h3 class="anchored" data-anchor-id="chi-squared-test-複習">Chi-squared Test 複習</h3>
<p>假設我們有個 contingency table (列聯表) 如下：</p>
<table class="caption-top table">
<thead>
<tr class="header">
<th></th>
<th>Category 1</th>
<th>Category 2</th>
<th>Category 3</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Group A</td>
<td>10</td>
<td>20</td>
<td>30</td>
<td>60</td>
</tr>
<tr class="even">
<td>Group B</td>
<td>10</td>
<td>15</td>
<td>15</td>
<td>40</td>
</tr>
<tr class="odd">
<td>Total</td>
<td>20</td>
<td>35</td>
<td>45</td>
<td>100</td>
</tr>
</tbody>
</table>
<p>我們想知道 Group A 跟 Group B 在這三個 category 上是否有顯著差異 (independence)。我們可以使用 Chi-squared test 來檢驗這個假設。</p>
<p><strong>步驟一、計算期望值 (Expected Counts)</strong>： 根據獨立性的假設，也就是這個 contingency table 是一個 rank 1 矩陣，我們可以計算每個 cell 的期望值：</p>
<table class="caption-top table">
<colgroup>
<col style="width: 23%">
<col style="width: 25%">
<col style="width: 25%">
<col style="width: 25%">
</colgroup>
<thead>
<tr class="header">
<th></th>
<th>Category 1</th>
<th>Category 2</th>
<th>Category 3</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Group A</td>
<td>(60*20)/100 = 12</td>
<td>(60*35)/100 = 21</td>
<td>(60*45)/100 = 27</td>
</tr>
<tr class="even">
<td>Group B</td>
<td>(40*20)/100 = 8</td>
<td>(40*35)/100 = 14</td>
<td>(40*45)/100 = 18</td>
</tr>
</tbody>
</table>
<p><strong>步驟二、計算 Chi-squared 統計量</strong>： <img src="https://latex.codecogs.com/png.latex?%0A%5Cchi%5E2%20=%20%5Csum%20%5Cfrac%7B(O%20-%20E)%5E2%7D%7BE%7D%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?O"> 是觀察值 (Observed Counts)，<img src="https://latex.codecogs.com/png.latex?E"> 是期望值 (Expected Counts)。 計算如下： <img src="https://latex.codecogs.com/png.latex?%0A%5Cchi%5E2%20=%20%5Cfrac%7B(10-12)%5E2%7D%7B12%7D%20+%20%5Cfrac%7B(20-21)%5E2%7D%7B21%7D%20+%20%5Cfrac%7B(30-27)%5E2%7D%7B27%7D%20+%20%5Cfrac%7B(10-8)%5E2%7D%7B8%7D%20+%20%5Cfrac%7B(15-14)%5E2%7D%7B14%7D%20+%20%5Cfrac%7B(15-18)%5E2%7D%7B18%7D%20%5Capprox%202.38%0A"></p>
<p><strong>步驟三、決定自由度 (Degrees of Freedom)</strong>： 自由度計算公式為： <img src="https://latex.codecogs.com/png.latex?%0Adf%20=%20(r%20-%201)(c%20-%201)%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?r"> 是列數，<img src="https://latex.codecogs.com/png.latex?c"> 是行數。在這個例子中，<img src="https://latex.codecogs.com/png.latex?r=2">，<img src="https://latex.codecogs.com/png.latex?c=3">，所以 <img src="https://latex.codecogs.com/png.latex?df%20=%20(2-1)(3-1)%20=%202">。</p>
<p><strong>步驟四、查表或計算 p-value</strong>： 我們可以使用 Chi-squared 分布表或計算 p-value 來判斷。我們查表發現，當 <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2%20%5Capprox%202.38"> 且 <img src="https://latex.codecogs.com/png.latex?df=2"> 時，p-value 約為 0.3。</p>
<p>由於 p-value 大於常見的顯著水準 (如 0.05)，我們無法拒絕獨立性的假設，表示 Group A 跟 Group B 在這三個 category 上沒有顯著差異。</p>
<p>Chi-squared Test 是說，當樣本數很大(超過30)，這個統計量會趨近於 Chi-squared 分布 (degrees of freedom = (r-1)(c-1))。本質上他本來就永遠不會真正等於 Chi-squared 分布，因為他是離散的。所以這邊談的是個趨近的概念。</p>
<p>其實第一次看到這個公式覺得很不舒服，為什麼要這樣算? 更直觀的算法應該是某種 statistic distance，比方說 <img src="https://latex.codecogs.com/png.latex?%0A%5Csum%20%7Cp_i%20-%20q_i%7C%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?p_i"> 是觀察到的比例，<img src="https://latex.codecogs.com/png.latex?q_i"> 是期望的比例。</p>
<p>身為數學家想要最優化的靈魂開始作祟，這樣為甚麼是最好的? 我們通常想找一個「最有效力的檢定方法 (most powerful test)」，而實在看不出來這個是。</p>
</section>
<section id="intuition-解釋版本1" class="level3">
<h3 class="anchored" data-anchor-id="intuition-解釋版本1">Intuition 解釋版本1</h3>
<p>我們直觀地理解 Chi-squared test，應該這樣解讀公式 <img src="https://latex.codecogs.com/png.latex?%0A%5Csum%20%5Cfrac%7B(O-E)%5E2%7D%7BE%7D%20=%20%5Csum%20%5Cleft(%5Cfrac%7BO-E%7D%7B%5Csqrt%7BE%7D%7D%5Cright)%5E2%0A"> 還記得如果是 binomial 分佈(或者看成 multinomial 分布的其中一項)，期望值是 <img src="https://latex.codecogs.com/png.latex?np">，標準差是 <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7Bnp(1-p)%7D">，所以若 <img src="https://latex.codecogs.com/png.latex?E"> 是期望值，那 <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7BE%7D"> 大概是標準差 (忽略掉 <img src="https://latex.codecogs.com/png.latex?1-p"> 部分)。所以我們就是在算 實際值 <img src="https://latex.codecogs.com/png.latex?O"> 減去 期望值 <img src="https://latex.codecogs.com/png.latex?E"> 再除以標準差 <img src="https://latex.codecogs.com/png.latex?%5Csqrt%7BE%7D">，這就是標準化 (standardization) z-score的概念。然後我們把每個 category 的標準化結果平方後加總起來，這就是 Chi-squared 統計量。</p>
<p>這個解釋對於公式來說是最直觀的，但也忽略了很多細節，比方說這忽略的 <img src="https://latex.codecogs.com/png.latex?(1-p)"> 感覺不會趨近於 0，而且為甚麼自由度是 <img src="https://latex.codecogs.com/png.latex?(r-1)(c-1)">，這些不同z-score之間並沒有獨立，怎麼可以說是Chi-squared?</p>
</section>
<section id="intution-解釋版本2" class="level3">
<h3 class="anchored" data-anchor-id="intution-解釋版本2">Intution 解釋版本2</h3>
<p>另一個角度，我們證明這其實是個 likelihood ratio test 的近似，而 likelihood ratio test 本身就是最有效力的檢定方法 (Neyman-Pearson lemma)。</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?H_0">: Contigency table 是 rank 1 矩陣 (independent)。用 <img src="https://latex.codecogs.com/png.latex?r+c-2"> 個參數描述。</li>
<li><img src="https://latex.codecogs.com/png.latex?H_1">: Contigency table 是 任意的矩陣。用 <img src="https://latex.codecogs.com/png.latex?rc%20-1"> 個參數描述。</li>
</ul>
<p>我們可以計算在 <img src="https://latex.codecogs.com/png.latex?H_0"> 跟 <img src="https://latex.codecogs.com/png.latex?H_1"> 下的 likelihood ratio。</p>
<p><strong>先算 <img src="https://latex.codecogs.com/png.latex?H_0">:</strong></p>
<p>假設我們實驗得到的表是 <img src="https://latex.codecogs.com/png.latex?O_%7Bij%7D">，<img src="https://latex.codecogs.com/png.latex?N%20=%20%5Csum_%7Bi,j%7D%20O_%7Bij%7D">。用 rank 1 矩陣去算 likelihood 就是待定 <img src="https://latex.codecogs.com/png.latex?a_i"> 跟 <img src="https://latex.codecogs.com/png.latex?b_j"> (滿足 <img src="https://latex.codecogs.com/png.latex?%5Csum_i%20a_i%20=%201"> 且 <img src="https://latex.codecogs.com/png.latex?%5Csum_j%20b_j%20=%201">)，把 <img src="https://latex.codecogs.com/png.latex?a_i%20b_j%20N"> 當成期望值。</p>
<p>likelihood function 是 multinomial distribution: <img src="https://latex.codecogs.com/png.latex?%0AL(H_0)%20:=%20%5Cmathbb%7BP%7D_0(O%20%5Cmid%20a_i,%20b_j)%20=%20%5Cbinom%7BN%7D%7BO_%7B11%7D,%20O_%7B12%7D,%20%5Cldots,%20O_%7Brc%7D%7D%20%5Cprod_%7Bi,j%7D%20(a_i%20b_j)%5E%7BO_%7Bij%7D%7D%0A"> 這邊我們要選 <img src="https://latex.codecogs.com/png.latex?a_i,%20b_j"> 使得 likelihood 最大化。不防忽略常數項，然後取 log: <img src="https://latex.codecogs.com/png.latex?%0A%5Clog%20L(H_0)%20=%20%5Csum_%7Bi,j%7D%20O_%7Bij%7D%20(%5Clog%20a_i%20+%20%5Clog%20b_j)%0A"> 因為還有約束條件 <img src="https://latex.codecogs.com/png.latex?%5Csum_i%20a_i%20=%201">，<img src="https://latex.codecogs.com/png.latex?%5Csum_j%20b_j%20=%201">，我們用拉格朗日乘數法 (Lagrange multipliers)，引入 <img src="https://latex.codecogs.com/png.latex?%5Clambda,%20%5Cmu">，考慮 <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BL%7D(a_i,%20b_j,%20%5Clambda,%20%5Cmu)%20=%20%5Csum_%7Bi,j%7D%20O_%7Bij%7D%20(%5Clog%20a_i%20+%20%5Clog%20b_j)%20+%20%5Clambda%20(1%20-%20%5Csum_i%20a_i)%20+%20%5Cmu%20(1%20-%20%5Csum_j%20b_j)%0A"> 分別對 <img src="https://latex.codecogs.com/png.latex?a_i">, <img src="https://latex.codecogs.com/png.latex?b_j"> 求導數並設為 0: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20a_i%7D%20&amp;=%20%5Csum_j%20%5Cfrac%7BO_%7Bij%7D%7D%7Ba_i%7D%20-%20%5Clambda%20=%200%20%5Cimplies%20a_i%20=%20%5Cfrac%7B%5Csum_j%20O_%7Bij%7D%7D%7B%5Clambda%7D%20%5C%5C%0A%5Cfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20b_j%7D%20&amp;=%20%5Csum_i%20%5Cfrac%7BO_%7Bij%7D%7D%7Bb_j%7D%20-%20%5Cmu%20=%200%20%5Cimplies%20b_j%20=%20%5Cfrac%7B%5Csum_i%20O_%7Bij%7D%7D%7B%5Cmu%7D%0A%5Cend%7Balign%7D%0A"> 利用約束條件，我們可以解出 <img src="https://latex.codecogs.com/png.latex?%5Clambda=%5Cmu=%5Csum_%7Bi,j%7D%20O_%7Bij%7D%20=%20N">，所以期望值 <img src="https://latex.codecogs.com/png.latex?%0Aa_i%20b_j%20N%20=%20%5Cfrac%7B%5Csum_j%20O_%7Bij%7D%20%5Csum_i%20O_%7Bij%7D%7D%7BN%7D%20=%20E_%7Bij%7D%0A"> 這就是我們在 Chi-squared test 裡面計算的期望值。 代回去 likelihood function: <img src="https://latex.codecogs.com/png.latex?%0AL(H_0)%20=%20%5Cbinom%7BN%7D%7BO_%7B11%7D,%20O_%7B12%7D,%20%5Cldots,%20O_%7Brc%7D%7D%20%5Cprod_%7Bi,j%7D%20%5Cleft(%5Cfrac%7BE_%7Bij%7D%7D%7BN%7D%5Cright)%5E%7BO_%7Bij%7D%7D%0A=%20%5Cbinom%7BN%7D%7BO_%7B11%7D,%20O_%7B12%7D,%20%5Cldots,%20O_%7Brc%7D%7D%20%5Cfrac%7B1%7D%7BN%5EN%7D%5Cprod_%7Bi,j%7D%20E_%7Bij%7D%5E%7BO_%7Bij%7D%7D%0A"></p>
<p><strong>接著來算 <img src="https://latex.codecogs.com/png.latex?H_1">:</strong></p>
<p>過程很類似，但現在有 <img src="https://latex.codecogs.com/png.latex?rc-1"> 個參數 <img src="https://latex.codecogs.com/png.latex?p_%7Bij%7D">，且約束條件是 <img src="https://latex.codecogs.com/png.latex?%5Csum_%7Bi,j%7D%20p_%7Bij%7D%20=%201">。直接算 Lagrangian: <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BL%7D(p_%7Bij%7D,%20%5Clambda)%20=%20%5Csum_%7Bi,j%7D%20O_%7Bij%7D%20%5Clog%20p_%7Bij%7D%20+%20%5Clambda%20(1%20-%20%5Csum_%7Bi,j%7D%20p_%7Bij%7D)%0A"> 取偏導並設為 0: <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20p_%7Bij%7D%7D%20=%20%5Cfrac%7BO_%7Bij%7D%7D%7Bp_%7Bij%7D%7D%20-%20%5Clambda%20=%200%20%5Cimplies%20p_%7Bij%7D%20=%20%5Cfrac%7BO_%7Bij%7D%7D%7B%5Clambda%7D%20=%20%5Cfrac%7BO_%7Bij%7D%7D%7BN%7D%0A"> 所以期望值就是觀察值本身 <img src="https://latex.codecogs.com/png.latex?O_%7Bij%7D">，非常符合直覺。代回去 likelihood function: <img src="https://latex.codecogs.com/png.latex?%0AL(H_1)%20=%20%5Cbinom%7BN%7D%7BO_%7B11%7D,%20O_%7B12%7D,%20%5Cldots,%20O_%7Brc%7D%7D%20%5Cprod_%7Bi,j%7D%20%5Cleft(%5Cfrac%7BO_%7Bij%7D%7D%7BN%7D%5Cright)%5E%7BO_%7Bij%7D%7D%0A=%20%5Cbinom%7BN%7D%7BO_%7B11%7D,%20O_%7B12%7D,%20%5Cldots,%20O_%7Brc%7D%7D%20%5Cfrac%7B1%7D%7BN%5EN%7D%5Cprod_%7Bi,j%7D%20O_%7Bij%7D%5E%7BO_%7Bij%7D%7D%0A"></p>
<p><strong>最後計算 likelihood ratio:</strong> <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5CLambda%20&amp;=%20%5Cfrac%7BL(H_0)%7D%7BL(H_1)%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B%5Cprod_%7Bi,j%7D%20E_%7Bij%7D%5E%7BO_%7Bij%7D%7D%7D%7B%5Cprod_%7Bi,j%7D%20O_%7Bij%7D%5E%7BO_%7Bij%7D%7D%7D%20%5C%5C%0A&amp;=%20%5Cprod_%7Bi,j%7D%20%5Cleft(%5Cfrac%7BE_%7Bij%7D%7D%7BO_%7Bij%7D%7D%5Cright)%5E%7BO_%7Bij%7D%7D%0A%5Cend%7Balign%7D%0A"></p>
</section>
<section id="interactive-finite-chi-square-cdf-log-scale" class="level3">
<h3 class="anchored" data-anchor-id="interactive-finite-chi-square-cdf-log-scale">Interactive: Finite Chi-Square CDF (Log Scale)</h3>
<p>Adjust <img src="https://latex.codecogs.com/png.latex?n"> to see how the discrete CDF steps approximate the smooth curve.</p>
<div class="cell">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb1" data-startfrom="154" data-source-offset="0" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 153;"><span id="cb1-154">viewof n <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> Inputs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>([<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">50</span>]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">value</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">step</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Sample Size (n)"</span>})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div id="ojs-cell-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="panel-fill panel-grid">
<div class="g-col-24">
<div class="cell panel-fill">
<div class="code-copy-outer-scaffold"><div class="sourceCode cell-code hidden" id="cb2" data-startfrom="163" data-source-offset="-29" style="background: #f1f3f5;"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript" style="counter-reset: source-line 162;"><span id="cb2-163">probs <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.3</span>] <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Change probabilities here</span></span>
<span id="cb2-164">k <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> probs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">length</span></span>
<span id="cb2-165">expected <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> probs<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(p <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> n)</span>
<span id="cb2-166"></span>
<span id="cb2-167"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// --- 2. MATH LOGIC ---</span></span>
<span id="cb2-168"></span>
<span id="cb2-169"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Recursive function to get partitions (compositions of integer n)</span></span>
<span id="cb2-170"><span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">function</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getCompositions</span>(target<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> bins) {</span>
<span id="cb2-171">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (bins <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> [[target]]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-172">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> results <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> []<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-173">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span> (<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> target<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) {</span>
<span id="cb2-174">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> sub <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getCompositions</span>(target <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> bins <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-175">    sub<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(s <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> results<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">push</span>([i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">...</span>s]))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-176">  }</span>
<span id="cb2-177">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> results<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-178">}</span>
<span id="cb2-179"></span>
<span id="cb2-180"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Generate Raw Data</span></span>
<span id="cb2-181">outcomes <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">getCompositions</span>(n<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> k)</span>
<span id="cb2-182"></span>
<span id="cb2-183">rawData <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> outcomes<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(counts <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-184">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Factorial helper</span></span>
<span id="cb2-185">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> fact <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (num) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-186">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">if</span> (num <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span>) <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-187">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> </span>
<span id="cb2-188">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">for</span>(<span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">&lt;=</span>num<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">++</span>) r <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*=</span> i<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> </span>
<span id="cb2-189">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> r<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-190">  }</span>
<span id="cb2-191">  </span>
<span id="cb2-192">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Multinomial Prob</span></span>
<span id="cb2-193">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> denom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-194">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> probTerm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-195">  counts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>((c<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-196">    denom <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*=</span> <span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fact</span>(c)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-197">    probTerm <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pow</span>(probs[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> c)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-198">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-199">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> p <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> (<span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">fact</span>(n) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> denom) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> probTerm<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-200">  </span>
<span id="cb2-201">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Chi Sq Statistic</span></span>
<span id="cb2-202">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-203">  counts<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>((c<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> i) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-204">    q <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">pow</span>(c <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> expected[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span> expected[i]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-205">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-206">  </span>
<span id="cb2-207">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">q</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> p}<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-208">})</span>
<span id="cb2-209"></span>
<span id="cb2-210"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// --- 3. AGGREGATE &amp; CALCULATE CDF ---</span></span>
<span id="cb2-211"></span>
<span id="cb2-212">groupedCDF <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> {</span>
<span id="cb2-213">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// A. Group by Q (sum probabilities for identical Q statistics)</span></span>
<span id="cb2-214">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> map <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">new</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Map</span>()<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-215">  rawData<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">forEach</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-216">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> key <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">6</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span> </span>
<span id="cb2-217">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> existing <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">get</span>(key) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">||</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-218">    map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">set</span>(key<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> existing <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-219">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-220">  </span>
<span id="cb2-221">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// B. Sort by Q</span></span>
<span id="cb2-222">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> sorted <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Array</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">from</span>(map<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> ([q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> p]) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">q</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span>q<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> p}))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">sort</span>((a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span>b) <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> a<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> b<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-223">  </span>
<span id="cb2-224">  <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// C. Calculate Cumulative Sum</span></span>
<span id="cb2-225">  <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">let</span> cumSum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-226">  <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> sorted<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> {</span>
<span id="cb2-227">    cumSum <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+=</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">p</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-228">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Log scale fix: If Q is exactly 0, bump it to 0.01 so it shows up on log axis</span></span>
<span id="cb2-229">    <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">const</span> plotQ <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">=</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">===</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">?</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-230">    <span class="cf" style="color: #003B4F;
background-color: null;
font-style: inherit;">return</span> {</span>
<span id="cb2-231">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">realQ</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">q</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-232">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">plotQ</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> plotQ<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb2-233">      <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">cdf</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> cumSum</span>
<span id="cb2-234">    }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-235">  })<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">;</span></span>
<span id="cb2-236">}</span>
<span id="cb2-237"></span>
<span id="cb2-238"><span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// --- 4. PLOTTING ---</span></span>
<span id="cb2-239"></span>
<span id="cb2-240">Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">plot</span>({</span>
<span id="cb2-241">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`CDF for n=</span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>n<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;"> (Log Scale)`</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-242">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">grid</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">true</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-243">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb2-244">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">type</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"log"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb2-245">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Chi-Square Statistic (Q)"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-246">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(groupedCDF<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">realQ</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">*</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.2</span>] <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Ensure plot fits</span></span>
<span id="cb2-247">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-248">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> {</span>
<span id="cb2-249">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">label</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"Cumulative Probability"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> </span>
<span id="cb2-250">    <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">domain</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">0</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">1.05</span>]</span>
<span id="cb2-251">  }<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-252">  <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">marks</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> [</span>
<span id="cb2-253">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// The "Sticks" (Discrete CDF)</span></span>
<span id="cb2-254">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">ruleY</span>(groupedCDF<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plotQ"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cdf"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2563eb"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-255">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">dot</span>(groupedCDF<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"plotQ"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"cdf"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#2563eb"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">r</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">3</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">title</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> <span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`Q: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">realQ</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}\n</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">CDF: </span><span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">${</span>d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">cdf</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">toFixed</span>(<span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">4</span>)<span class="sc" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">}</span><span class="vs" style="color: #20794D;
background-color: null;
font-style: inherit;">`</span>})<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-256">    </span>
<span id="cb2-257">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// The Continuous Chi-Square CDF Curve (df = 2)</span></span>
<span id="cb2-258">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Formula: 1 - exp(-x/2)</span></span>
<span id="cb2-259">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">line</span>(</span>
<span id="cb2-260">       d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">range</span>(<span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d3<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">max</span>(groupedCDF<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> d <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> d<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="at" style="color: #657422;
background-color: null;
font-style: inherit;">realQ</span>) <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">+</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">5</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span>)<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">map</span>(x <span class="kw" style="color: #003B4F;
background-color: null;
font-style: inherit;">=&gt;</span> ({<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">1</span> <span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span> <span class="bu" style="color: null;
background-color: null;
font-style: inherit;">Math</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">exp</span>(<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">-</span>x<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">/</span><span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>)}))<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-261">      {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">stroke</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"#dc2626"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">strokeWidth</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">2</span>}</span>
<span id="cb2-262">    )<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span></span>
<span id="cb2-263">    </span>
<span id="cb2-264">    <span class="co" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">// Add a text annotation explaining the log clamp if needed</span></span>
<span id="cb2-265">    Plot<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">.</span><span class="fu" style="color: #4758AB;
background-color: null;
font-style: inherit;">text</span>([{<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.01</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="fl" style="color: #AD0000;
background-color: null;
font-style: inherit;">0.1</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">text</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"← Q=0 (Clamped)"</span>}]<span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> {<span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">x</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"x"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">y</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"y"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">textAnchor</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"start"</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fontSize</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="dv" style="color: #AD0000;
background-color: null;
font-style: inherit;">10</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">,</span> <span class="dt" style="color: #AD0000;
background-color: null;
font-style: inherit;">fill</span><span class="op" style="color: #5E5E5E;
background-color: null;
font-style: inherit;">:</span> <span class="st" style="color: #20794D;
background-color: null;
font-style: inherit;">"gray"</span>})</span>
<span id="cb2-266">  ]</span>
<span id="cb2-267">})</span></code></pre></div></div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-1" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-2" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-3" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-4" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-5" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-6" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-7" data-nodetype="declaration">

</div>
</div>
</div>
<div class="cell-output cell-output-display">
<div>
<div id="ojs-cell-2-8" data-nodetype="expression">

</div>
</div>
</div>
</div>
</div>
</div>
</section>
<section id="why-this-works" class="level3">
<h3 class="anchored" data-anchor-id="why-this-works">Why this works:</h3>
<ol type="1">
<li><strong><code>viewof n = Inputs.range(...)</code></strong>: Creates the HTML slider.</li>
<li><strong><code>{ojs}</code> block</strong>: This JavaScript code runs in the user’s browser, not on your server.</li>
<li><strong>Reactivity</strong>: When the user drags the slider, <code>n</code> updates, the <code>data</code> array recalculates, and <code>Plot.plot</code> re-renders automatically.</li>
</ol>
<p><strong>Note:</strong> I hardcoded the Chi-Square PDF for <img src="https://latex.codecogs.com/png.latex?k=3"> (df=2) as <img src="https://latex.codecogs.com/png.latex?0.5e%5E%7B-x/2%7D"> to avoid needing a complex Gamma function library in JavaScript. If you change the number of probabilities (<img src="https://latex.codecogs.com/png.latex?k">), you will need to update that formula.</p>


</section>

 ]]></description>
  <category>Normal Distribution</category>
  <guid>https://your-website-url.example.com/posts/normal-distribution/day_6.html</guid>
  <pubDate>Thu, 20 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>一天證明一個 Normal Distribution 的性質 Day5：獨立性的量尺: Cumulant</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/normal-distribution/day_5.html</link>
  <description><![CDATA[ 




<p>今天來講個輕鬆的小主題：<strong>Cumulant</strong>。</p>
<p>對於一個隨機變數 <img src="https://latex.codecogs.com/png.latex?X">，我們通常想知道平均跟標準差。有時候我們甚至會想知道更高階的資訊，例如偏度 (skewness) 跟峰度 (kurtosis)，這些都可以透過動差 (moment) 來描述。</p>
<section id="cumulant-generating-function" class="level3">
<h3 class="anchored" data-anchor-id="cumulant-generating-function">Cumulant Generating Function</h3>
<p>還記得動差生成函數 (Moment Generating Function, MGF) 定義為： <img src="https://latex.codecogs.com/png.latex?%20%20%0AM_X(t)%20=%20%5Cmathbb%7BE%7D%5Be%5E%7BtX%7D%5D%20=%20%5Csum_%7Bk=0%7D%5E%7B%5Cinfty%7D%20%5Cmathbb%7BE%7D%5BX%5E%7Bk%7D%5D%20%5Cfrac%7Bt%5Ek%7D%7Bk!%7D%0A"> 名符其實，他就是「動差」的生成函數，因為對 <img src="https://latex.codecogs.com/png.latex?M_X(t)"> 做泰勒展開 (Taylor Expansion) 後，係數正好是各階 <strong>動差</strong> (moment)： <img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_k'%20:=%20%5Cmathbb%7BE%7D%5BX%5Ek%5D%20=%20M_X%5E%7B(k)%7D(0)%20=%20%5Cleft.%20%5Cfrac%7Bd%5Ek%7D%7Bdt%5Ek%7D%20M_X(t)%20%5Cright%7C_%7Bt=0%7D%20%20%5Ctag%7B1%7D%5Clabel%7Beq:moment_def_1%7D%0A"> 另外一種比較常用的是減掉常數項的<strong>中心動差</strong> (central moment)： <img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_k%20:=%20%5Cmathbb%7BE%7D%5B(X%20-%20%5Cmathbb%7BE%7D%5BX%5D)%5Ek%5D%0A"></p>
<p>不過呢，有時候因為動差函數不存在 (例如 Cauchy 分佈)，我們會改用一定會存在的特徵函數 (Characteristic Function, CF)： <img src="https://latex.codecogs.com/png.latex?%0A%5Cphi_X(t)%20=%20%5Cmathbb%7BE%7D%5Be%5E%7BitX%7D%5D%20=%20%5Csum_%7Bk=0%7D%5E%7B%5Cinfty%7D%20%5Cmathbb%7BE%7D%5BX%5E%7Bk%7D%5D%20%5Cfrac%7B(it)%5Ek%7D%7Bk!%7D%0A"> 所以也可以用 <img src="https://latex.codecogs.com/png.latex?%5Cphi_X(t)"> 來計算動差： <img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_k'%20=%20%5Cmathbb%7BE%7D%5BX%5Ek%5D%20=%20%5Cfrac%7B1%7D%7Bi%5Ek%7D%20%5Cphi_X%5E%7B(k)%7D(0)%20=%20%5Cleft.%20%5Cfrac%7B1%7D%7Bi%5Ek%7D%20%5Cfrac%7Bd%5Ek%7D%7Bdt%5Ek%7D%20%5Cphi_X(t)%20%5Cright%7C_%7Bt=0%7D%20%20%5Ctag%7B2%7D%5Clabel%7Beq:moment_def_2%7D%0A"> 至於 central moment， <img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_k%20=%20%5Cmathbb%7BE%7D%5B(X%20-%20%5Cmathbb%7BE%7D%5BX%5D)%5Ek%5D%20=%20%5Cfrac%7B1%7D%7Bi%5Ek%7D%20%5Cfrac%7Bd%5Ek%7D%7Bdt%5Ek%7D%20%5Cleft%5B%20e%5E%7B-it%20%5Cmu_1'%7D%20%5Cphi_X(t)%20%5Cright%5D_%7Bt=0%7D%0A"> 這邊要稍微注意一下，CF 是個複數值函數，所以其實是個複變函數的微分!</p>
<p><strong>舉例說明</strong>：</p>
<table class="caption-top table">
<colgroup>
<col style="width: 4%">
<col style="width: 14%">
<col style="width: 19%">
<col style="width: 17%">
<col style="width: 22%">
<col style="width: 21%">
</colgroup>
<thead>
<tr class="header">
<th>Distribution</th>
<th><img src="https://latex.codecogs.com/png.latex?%5Cphi_X(t)"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Bd%7D%7Bdt%7D%5Cphi_X(t)"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5BX%5D"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Bd%5E2%7D%7Bdt%5E2%7D%5Cphi_X(t)"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BE%7D%5BX%5E2%5D"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Bernoulli(<img src="https://latex.codecogs.com/png.latex?p">)</td>
<td><img src="https://latex.codecogs.com/png.latex?1%20-%20p%20+%20p%20e%5E%7Bit%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?ip%20e%5E%7Bit%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?p"></td>
<td><img src="https://latex.codecogs.com/png.latex?-p%20e%5E%7Bit%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?p"></td>
</tr>
<tr class="even">
<td>Poisson(<img src="https://latex.codecogs.com/png.latex?%5Clambda">)</td>
<td><img src="https://latex.codecogs.com/png.latex?e%5E%7B%5Clambda(e%5E%7Bit%7D-1)%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?i%5Clambda%20e%5E%7Bit%7D%20e%5E%7B%5Clambda(e%5E%7Bit%7D-1)%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
<td><img src="https://latex.codecogs.com/png.latex?-%5Clambda%20e%5E%7Bit%7D%20e%5E%7B%5Clambda(e%5E%7Bit%7D-1)%7D%20+%20(i%5Clambda%20e%5E%7Bit%7D)%5E2%20e%5E%7B%5Clambda(e%5E%7Bit%7D-1)%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Clambda%20+%20%5Clambda%5E2"></td>
</tr>
<tr class="odd">
<td>Normal(<img src="https://latex.codecogs.com/png.latex?%5Cmu,%20%5Csigma%5E2">)</td>
<td><img src="https://latex.codecogs.com/png.latex?e%5E%7Bi%5Cmu%20t%20-%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?i%5Cmu%20e%5E%7Bi%5Cmu%20t%20-%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D%20-%20%5Csigma%5E2%20t%20e%5E%7Bi%5Cmu%20t%20-%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cmu"></td>
<td><img src="https://latex.codecogs.com/png.latex?-%5Csigma%5E2%20e%5E%7Bi%5Cmu%20t%20-%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D%20+%20(i%5Cmu%20-%20%5Csigma%5E2%20t)%5E2%20e%5E%7Bi%5Cmu%20t%20-%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2%20+%20%5Cmu%5E2"></td>
</tr>
<tr class="even">
<td>Gamma(<img src="https://latex.codecogs.com/png.latex?%5Calpha,%20%5Ctheta">)</td>
<td><img src="https://latex.codecogs.com/png.latex?(1%20-%20i%5Ctheta%20t)%5E%7B-%5Calpha%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?i%5Calpha%20%5Ctheta%20(1%20-%20i%5Ctheta%20t)%5E%7B-%5Calpha%20-%201%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Ctheta"></td>
<td><img src="https://latex.codecogs.com/png.latex?-%20%5Calpha%20(%5Calpha%20+%201)%20%5Ctheta%5E2%20(1%20-%20i%5Ctheta%20t)%5E%7B-%5Calpha%20-%202%7D"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Calpha%20(%5Calpha%20+%201)%20%5Ctheta%5E2"></td>
</tr>
</tbody>
</table>
<p>而如果只是想算 moment 的話 CF 就很夠用，但他對於捕捉獨立性 (independence) 的效果並不理想。這時候我們就需要用到 <strong>Cumulant Generating Function (CGF)</strong>： <img src="https://latex.codecogs.com/png.latex?%0AK_X(t)%20=%20%5Clog%20M_X(t)%20=%20%5Clog%20%5Cmathbb%7BE%7D%5Be%5E%7BtX%7D%5D%20%20%5Ctag%7B3%7D%5Clabel%7Beq:cumulant_gf_def%7D%0A"><br>
因此我們定義 Cumulant 為： <img src="https://latex.codecogs.com/png.latex?%0A%5Ckappa_k%20:=%20K_X%5E%7B(k)%7D(0)%20=%20%5Cleft.%20%5Cfrac%7Bd%5Ek%7D%7Bdt%5Ek%7D%20K_X(t)%20%5Cright%7C_%7Bt=0%7D%20%20%5Ctag%7B4%7D%5Clabel%7Beq:cumulant_def_1%7D%0A"></p>
<p>當然，也有複數版本，通常會叫 Second Characteristic Function： <img src="https://latex.codecogs.com/png.latex?%0AH_X(t)%20=%20%5Clog%20%5Cphi_X(t)%20=%20%5Clog%20%5Cmathbb%7BE%7D%5Be%5E%7BitX%7D%5D%20%20%5Ctag%7B5%7D%5Clabel%7Beq:second_char_def%7D%0A"> 但這有個問題，就是 <img src="https://latex.codecogs.com/png.latex?%5Cphi_X(t)"> 可能會是負數或複數，導致 <img src="https://latex.codecogs.com/png.latex?%5Clog%20%5Cphi_X(t)"> 會有多重值 (multi-valued) 的問題，所以我們通常還是用實數版本的 CGF。</p>
<p>取了 <img src="https://latex.codecogs.com/png.latex?%5Clog"> 的好處就是：<strong>如果 <img src="https://latex.codecogs.com/png.latex?X"> 跟 <img src="https://latex.codecogs.com/png.latex?Y"> 獨立，那麼 <img src="https://latex.codecogs.com/png.latex?K_%7BX+Y%7D(t)%20=%20K_X(t)%20+%20K_Y(t)"></strong>。這點跟 MGF 不同，因為 MGF 是乘法關係 (<img src="https://latex.codecogs.com/png.latex?M_%7BX+Y%7D(t)%20=%20M_X(t)%20M_Y(t)">)。</p>
<p>所以對於 moment 來說，兩個獨立隨機變數相加的第 <img src="https://latex.codecogs.com/png.latex?n"> 階動差，會是兩個變數各自前 <img src="https://latex.codecogs.com/png.latex?n"> 階動差的 convolution (加上一些組合係數)。 但對於 cumulant 來說，兩個獨立隨機變數相加的第 <img src="https://latex.codecogs.com/png.latex?n"> 階 cumulant，會是兩個變數各自第 <img src="https://latex.codecogs.com/png.latex?n"> 階 cumulant 的<strong>直接相加</strong>： <img src="https://latex.codecogs.com/png.latex?%0A%5Ckappa_n(X%20+%20Y)%20=%20%5Ckappa_n(X)%20+%20%5Ckappa_n(Y)%20%5Cquad%20%5Ctext%7Bif%20%7D%20X%20%5Cperp%20Y%20%20%5Ctag%7B6%7D%5Clabel%7Beq:cumulant_indep_add%7D%0A"></p>
<p><strong>舉例說明</strong>：</p>
<table class="caption-top table">
<colgroup>
<col style="width: 6%">
<col style="width: 18%">
<col style="width: 25%">
<col style="width: 22%">
<col style="width: 27%">
</colgroup>
<thead>
<tr class="header">
<th>Distribution</th>
<th><img src="https://latex.codecogs.com/png.latex?%5Ckappa_1"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Ckappa_2"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Ckappa_3"></th>
<th><img src="https://latex.codecogs.com/png.latex?%5Ckappa_4"></th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Bernoulli(<img src="https://latex.codecogs.com/png.latex?p">)</td>
<td><img src="https://latex.codecogs.com/png.latex?p"></td>
<td><img src="https://latex.codecogs.com/png.latex?p(1-p)"></td>
<td><img src="https://latex.codecogs.com/png.latex?p(1-p)(1-2p)"></td>
<td><img src="https://latex.codecogs.com/png.latex?p(1-p)(1%20-%206p(1-p))"></td>
</tr>
<tr class="even">
<td>Poisson(<img src="https://latex.codecogs.com/png.latex?%5Clambda">)</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
</tr>
<tr class="odd">
<td>Normal(<img src="https://latex.codecogs.com/png.latex?%5Cmu,%20%5Csigma%5E2">)</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Cmu"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"></td>
<td><img src="https://latex.codecogs.com/png.latex?0"></td>
<td><img src="https://latex.codecogs.com/png.latex?0"></td>
</tr>
<tr class="even">
<td>Gamma(<img src="https://latex.codecogs.com/png.latex?%5Calpha,%20%5Ctheta">)</td>
<td><img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Ctheta"></td>
<td><img src="https://latex.codecogs.com/png.latex?%5Calpha%20%5Ctheta%5E2"></td>
<td><img src="https://latex.codecogs.com/png.latex?2%20%5Calpha%20%5Ctheta%5E3"></td>
<td><img src="https://latex.codecogs.com/png.latex?6%20%5Calpha%20%5Ctheta%5E4"></td>
</tr>
</tbody>
</table>
<p><strong>註</strong>: 直覺上因為 distribution 完全被 CF 決定，所以知道了所有 moment (或 cumulant) 似乎也就等於知道了 distribution 本身。但是，其實有可能 CF 在 0 點附近並不解析 (analytic)，常見例子請參考 Log-Normal distribution。所以說，知道所有 moment 只是知道在 0 點的微分，並不保證能還原整個 CF。</p>
<p>看著這個表，我們會想，是不是任意給 <img src="https://latex.codecogs.com/png.latex?%5Ckappa_1,%20%5Ckappa_2,%20%5Cldots,%20%5Ckappa_n">，就能找到一個對應的分佈？答案是否定的。比方說，若要使 cumulant 只有有限項非零，那麼這個分佈只能是 Normal 分佈，這是個非常有名的結果：</p>
<blockquote class="blockquote">
<p><strong>大定理(Marcinkiewicz Theorem)</strong>: 如果一個隨機變數的 cumulant generating function 是個(有限階)多項式，那麼這個多項式的階數最多是 2。</p>
</blockquote>
<p>為了保證 CGF 的存在性，該定理本來的敘述是說，若 CF 可以寫成 <img src="https://latex.codecogs.com/png.latex?%5Cphi_X(t)%20=%20e%5E%7BP(t)%7D">，其中 <img src="https://latex.codecogs.com/png.latex?P(t)"> 是個(複係數)多項式，那麼 <img src="https://latex.codecogs.com/png.latex?P(t)"> 的階數最多是 2。</p>
<p>我們先跳過證明，提供一些直覺上的理解：主要是因為 CF 是 PDF 的傅立葉變換，而 PDF 必須非負 (non-negative)，這使得 CF 的形式受到很大限制。<span class="citation" data-cites="lukacs1970">Lukacs (1970, Theorem 7.3.3)</span> 有詳細的證明。</p>
</section>
<section id="cumulant-vs-moment" class="level3">
<h3 class="anchored" data-anchor-id="cumulant-vs-moment">Cumulant vs Moment</h3>
<p>在一階、二階和三階，cumulant 跟 central moment 是一樣的: <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bd%7D%7Bdt%7D%20K_X(t)%20=%20%5Cfrac%7BM_X'(t)%7D%7BM_X(t)%7D%20%5Cimplies%20%5Ckappa_1%20=%20K_X'(0)%20=%20M_X'(0)%20=%20%5Cmu_1'%20=%20%5Cmathbb%7BE%7D%5BX%5D%0A"> <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cfrac%7Bd%5E2%7D%7Bdt%5E2%7D%20K_X(t)%20=%20%5Cfrac%7BM_X''(t)%7D%7BM_X(t)%7D%20-%20%5Cfrac%7BM_X'(t)%5E2%7D%7B(M_X(t))%5E2%7D%20%5C%5C%0A%5Cimplies%20&amp;%5Ckappa_2%20=%20K_X''(0)%20=%20M_X''(0)%20-%20(M_X'(0))%5E2%20=%20%5Cmu_2'%20-%20%5Cmu_1'%5E2%20=%20%5Cmathbb%7BE%7D%5B(X%20-%20%5Cmathbb%7BE%7D%5BX%5D)%5E2%5D%20=%20%5Cmu_2%0A%5Cend%7Balign%7D%0A"> 三階 cumulant 是： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cfrac%7Bd%5E3%7D%7Bdt%5E3%7D%20K_X(t)%20=%20%5Cfrac%7BM_X'''(t)%7D%7BM_X(t)%7D%20-%203%20%5Cfrac%7BM_X''(t)%20M_X'(t)%7D%7B(M_X(t))%5E2%7D%20+%202%20%5Cfrac%7B(M_X'(t))%5E3%7D%7B(M_X(t))%5E3%7D%20%5C%5C%0A%5Cimplies%20&amp;%5Ckappa_3%20=%20K_X'''(0)%20=%20M_X'''(0)%20-%203%20M_X''(0)%20M_X'(0)%20+%202%20(M_X'(0))%5E3%20%5C%5C%0A&amp;%5Cquad%20=%20%5Cmu_3'%20-%203%20%5Cmu_2'%20%5Cmu_1'%20+%202%20(%5Cmu_1')%5E3%20=%20%5Cmathbb%7BE%7D%5B(X%20-%20%5Cmathbb%7BE%7D%5BX%5D)%5E3%5D%20=%20%5Cmu_3%0A%5Cend%7Balign%7D%0A"> 但是從四階開始，cumulant 跟 central moment 就不一樣了： <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bd%5E4%7D%7Bdt%5E4%7D%20K_X(t)%20=%20%5Cfrac%7BM_X%5E%7B(4)%7D(t)%7D%7BM_X(t)%7D%20-%204%20%5Cfrac%7BM_X%5E%7B(3)%7D(t)%20M_X'(t)%7D%7B(M_X(t))%5E2%7D%20-%203%20%5Cfrac%7B(M_X''(t))%5E2%7D%7B(M_X(t))%5E2%7D%20+%2012%20%5Cfrac%7BM_X''(t)%20(M_X'(t))%5E2%7D%7B(M_X(t))%5E3%7D%20-%206%20%5Cfrac%7B(M_X'(t))%5E4%7D%7B(M_X(t))%5E4%7D%0A"> 所以我們有： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cimplies%20&amp;%5Ckappa_4%20=%20K_X%5E%7B(4)%7D(0)%20=%20M_X%5E%7B(4)%7D(0)%20-%204%20M_X%5E%7B(3)%7D(0)%20M_X'(0)%20-%203%20(M_X''(0))%5E2%20+%2012%20M_X''(0)%20(M_X'(0))%5E2%20-%206%20(M_X'(0))%5E4%20%5C%5C%0A&amp;%5Cquad%20=%20%5Cmu_4'%20-%204%20%5Cmu_3'%20%5Cmu_1'%20-%203%20(%5Cmu_2')%5E2%20+%2012%20%5Cmu_2'%20(%5Cmu_1')%5E2%20-%206%20(%5Cmu_1')%5E4%20%5C%5C%0A&amp;%5Cquad%20=%20%5Cmathbb%7BE%7D%5B(X%20-%20%5Cmathbb%7BE%7D%5BX%5D)%5E4%5D%20-%203%20(%5Cmathbb%7BE%7D%5B(X%20-%20%5Cmathbb%7BE%7D%5BX%5D)%5E2%5D)%5E2%20=%20%5Cmu_4%20-%203%20%5Cmu_2%5E2%0A%5Cend%7Balign%7D%0A"></p>
<p>由 cumulant 對於獨立變數相加的可加性質，我們可以由此看出，兩個獨立的隨機變數相加，平均值、變異數、偏度 都會相加，但峰度卻不會相加，因為峰度差了 <img src="https://latex.codecogs.com/png.latex?3%20%5Cmu_2%5E2">。而一般峰度的定義是 <img src="https://latex.codecogs.com/png.latex?%5Ctext%7BKurt%7D%5BX%5D%20=%20%5Cfrac%7B%5Cmu_4%7D%7B%5Cmu_2%5E2%7D">，所以峰度減去 3 (稱之為 excess kurtosis)，再搭配上適當的 variance scaling 就會有可加性。</p>
<p><strong>一般式的推導</strong></p>
<p>徒手算到這邊也差不多了。對於更高階的 cumulant，我們應該系統化地研究他們的係數。 因為 <img src="https://latex.codecogs.com/png.latex?M_X(t)%20=%20e%5E%7BK_X(t)%7D">，所以 <img src="https://latex.codecogs.com/png.latex?%5Cfrac%7BdM_X(t)%7D%7Bdt%7D%20=%20K_X'(t)%20e%5E%7BK_X(t)%7D%20=%20K_X'(t)%20M_X(t)">。</p>
<blockquote class="blockquote">
<p>乘法的微分 <img src="https://latex.codecogs.com/png.latex?n"> 階就會跟 二項式係數 有關: <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7Bd%5En%7D%7Bdt%5En%7D%20%5Bf(t)%20g(t)%5D%20=%20%5Csum_%7Bk=0%7D%5E%7Bn%7D%20%5Cbinom%7Bn%7D%7Bk%7D%20f%5E%7B(k)%7D(t)%20g%5E%7B(n-k)%7D(t)%0A"></p>
</blockquote>
<p>所以， <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0AM_X%5E%7B(n)%7D(t)%20&amp;=%20%5Cfrac%7Bd%5E%7Bn-1%7D%7D%7Bdt%5E%7Bn-1%7D%7D%20%5BK_X'(t)%20M_X(t)%5D%20%5C%5C%0A&amp;=%20%5Csum_%7Bm=0%7D%5E%7Bn-1%7D%20%5Cbinom%7Bn-1%7D%7Bm%7D%20K_X%5E%7B(n-m)%7D(t)%20M_X%5E%7B(m)%7D(t)%0A%5Cend%7Balign%7D%0A"> 將 <img src="https://latex.codecogs.com/png.latex?t=0"> 代入，因為 <img src="https://latex.codecogs.com/png.latex?M_X%5E%7B(0)%7D(0)%20=%201"> ，而 <img src="https://latex.codecogs.com/png.latex?M_X(t)"> 的 <img src="https://latex.codecogs.com/png.latex?n"> 階導數在 <img src="https://latex.codecogs.com/png.latex?0"> 就是動差 <img src="https://latex.codecogs.com/png.latex?%5Cmu_n'">，我們得到： <img src="https://latex.codecogs.com/png.latex?%0A%5Cmu_n'%20=%20%5Ckappa_%7Bn%7D%20+%20%5Csum_%7Bm=1%7D%5E%7Bn-1%7D%20%5Cbinom%7Bn-1%7D%7Bm%7D%20%5Ckappa_%7Bn-m%7D%20%5Cmu_%7Bm%7D'%20%20%5Ctag%7B7%7D%5Clabel%7Beq:moment_cumulant_relation%7D%0A"> 寫成矩陣形式會比較清楚： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bbmatrix%7D%0A%5Cmu_1'%20%5C%5C%0A%5Cmu_2'%20%5C%5C%0A%5Cmu_3'%20%5C%5C%0A%5Cmu_4'%20%5C%5C%0A%5Cmu_5'%20%5C%5C%0A%5Cvdots%0A%5Cend%7Bbmatrix%7D%0A=%0A%5Cbegin%7Bbmatrix%7D%0A1%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cbinom%7B1%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cbinom%7B2%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B2%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cbinom%7B3%7D%7B3%7D%20%5Cmu_3'%20&amp;%20%5Cbinom%7B3%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B3%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cbinom%7B4%7D%7B4%7D%20%5Cmu_4'%20&amp;%20%5Cbinom%7B4%7D%7B3%7D%20%5Cmu_3'%20&amp;%20%5Cbinom%7B4%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B4%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cvdots%20&amp;%20%5Cvdots%20&amp;%20%5Cvdots%20&amp;%20%5Cvdots%20&amp;%20%5Cvdots%20&amp;%20%5Cddots%0A%5Cend%7Bbmatrix%7D%0A%5Cbegin%7Bbmatrix%7D%0A%5Ckappa_1%20%5C%5C%0A%5Ckappa_2%20%5C%5C%0A%5Ckappa_3%20%5C%5C%0A%5Ckappa_4%20%5C%5C%0A%5Ckappa_5%20%5C%5C%0A%5Cvdots%0A%5Cend%7Bbmatrix%7D%0A"> 還是把 <img src="https://latex.codecogs.com/png.latex?%5Cmu_n'"> 全部寫在一起好了： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bbmatrix%7D%0A1%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cmu_2'%20&amp;%20%5Cbinom%7B1%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cmu_3'%20&amp;%20%5Cbinom%7B2%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B2%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cmu_4'%20&amp;%20%5Cbinom%7B3%7D%7B3%7D%20%5Cmu_3'%20&amp;%20%5Cbinom%7B3%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B3%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cmu_5'%20&amp;%20%5Cbinom%7B4%7D%7B4%7D%20%5Cmu_4'%20&amp;%20%5Cbinom%7B4%7D%7B3%7D%20%5Cmu_3'%20&amp;%20%5Cbinom%7B4%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B4%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%20%5Ccdots%20%5C%5C%0A%5Cvdots%20&amp;%20%5Cvdots%20&amp;%20%5Cvdots%20&amp;%20%5Cvdots%20&amp;%20%5Cvdots%20&amp;%20%5Cddots%0A%5Cend%7Bbmatrix%7D%0A%5Cbegin%7Bbmatrix%7D%0A-1%20%5C%5C%0A%5Ckappa_1%20%5C%5C%0A%5Ckappa_2%20%5C%5C%20%20%20%20%20%0A%5Ckappa_3%20%5C%5C%0A%5Ckappa_4%20%5C%5C%0A%5Ckappa_5%20%5C%5C%0A%5Cvdots%20%20%0A%5Cend%7Bbmatrix%7D%0A=%0A%5Cbegin%7Bbmatrix%7D%0A-1%20%5C%5C%0A0%20%5C%5C%0A0%20%5C%5C%0A0%20%5C%5C%0A0%20%5C%5C%0A0%20%5C%5C%0A%5Cvdots%0A%5Cend%7Bbmatrix%7D%0A"> 所以說要算任意的 <img src="https://latex.codecogs.com/png.latex?%5Ckappa_n">，我們就看這個矩陣的前 <img src="https://latex.codecogs.com/png.latex?(n+1)%20%5Ctimes%20(n+1)"> 子矩陣，然後套克拉瑪公式 (Cramer’s Rule)。 而且因為左邊矩陣行列式為 1，所以分母總是1。比方說來算 <img src="https://latex.codecogs.com/png.latex?%5Ckappa_5">，(最後一列是代右邊)： <img src="https://latex.codecogs.com/png.latex?%0A%5Ckappa_5%20=%0A%5Cbegin%7Bvmatrix%7D%0A1%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%20%5Ctextcolor%7Bblue%7D%7B-1%7D%20%5C%5C%0A%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%200%20&amp;%200%20&amp;%20%5Ctextcolor%7Bblue%7D%7B0%7D%20%5C%5C%0A%5Cmu_2'%20&amp;%20%5Cbinom%7B2%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%200%20&amp;%20%5Ctextcolor%7Bblue%7D%7B0%7D%20%5C%5C%0A%5Cmu_3'%20&amp;%20%5Cbinom%7B3%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B3%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%200%20&amp;%20%5Ctextcolor%7Bblue%7D%7B0%7D%20%5C%5C%0A%5Cmu_4'%20&amp;%20%5Cbinom%7B4%7D%7B3%7D%20%5Cmu_3'%20&amp;%20%5Cbinom%7B4%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B4%7D%7B1%7D%20%5Cmu_1'%20&amp;%201%20&amp;%20%5Ctextcolor%7Bblue%7D%7B0%7D%20%5C%5C%0A%5Cmu_5'%20&amp;%20%5Cbinom%7B5%7D%7B4%7D%20%5Cmu_4'%20&amp;%20%5Cbinom%7B5%7D%7B3%7D%20%5Cmu_3'%20&amp;%20%5Cbinom%7B5%7D%7B2%7D%20%5Cmu_2'%20&amp;%20%5Cbinom%7B5%7D%7B1%7D%20%5Cmu_1'%20&amp;%20%5Ctextcolor%7Bblue%7D%7B0%7D%0A%5Cend%7Bvmatrix%7D%0A"></p>



</section>

<div id="quarto-appendix" class="default"><section class="quarto-appendix-contents" id="quarto-bibliography"><h2 class="anchored quarto-appendix-heading">References</h2><div id="refs" class="references csl-bib-body hanging-indent" data-entry-spacing="0">
<div id="ref-lukacs1970" class="csl-entry">
Lukacs, Eugene. 1970. <em>Characteristic Functions</em>. 2nd ed. Griffin.
</div>
</div></section></div> ]]></description>
  <category>Normal Distribution</category>
  <guid>https://your-website-url.example.com/posts/normal-distribution/day_5.html</guid>
  <pubDate>Tue, 18 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>一天證明一個 Normal Distribution 的性質 Day4：充分統計量與消息理論</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/normal-distribution/day_4.html</link>
  <description><![CDATA[ 




<p>今天來講統計學中「參數估計」(Parameter Estimation) 一個非常優雅的概念：<strong>充分統計量 (Sufficient Statistic)</strong>。</p>
<p>假設我們從一個分佈 i.i.d. 取樣了 <img src="https://latex.codecogs.com/png.latex?n"> 個數據點： <img src="https://latex.codecogs.com/png.latex?%0AX_1,%20%5Cldots,%20X_n%20%5Csim%20P_%5Ctheta%0A"> 這個分佈包含一個未知的參數 <img src="https://latex.codecogs.com/png.latex?%5Ctheta">。原則上我們想估計這個 <img src="https://latex.codecogs.com/png.latex?%5Ctheta">（例如使用 Maximum Likelihood Estimation）。但在進行複雜估計之前，我們先思考一個問題：<strong>有沒有辦法把這 <img src="https://latex.codecogs.com/png.latex?n"> 個數據點「壓縮」成一個更小的統計量 (statistic)，同時完全不損失任何關於 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 的資訊？</strong> 這就是 Sufficient Statistic 的核心精神。</p>
<section id="從丟硬幣開始直觀的推導" class="level3">
<h3 class="anchored" data-anchor-id="從丟硬幣開始直觀的推導">從丟硬幣開始：直觀的推導</h3>
<p>以最簡單的丟硬幣為例。假設硬幣正面朝上的機率是未知的 <img src="https://latex.codecogs.com/png.latex?%5Ctheta">，<img src="https://latex.codecogs.com/png.latex?(0%20%3C%20%5Ctheta%20%3C%201)">。我們丟了 <img src="https://latex.codecogs.com/png.latex?n"> 次，得到結果 <img src="https://latex.codecogs.com/png.latex?X_1,%20%5Cldots,%20X_n">，其中 <img src="https://latex.codecogs.com/png.latex?X_i%20%5Cin%20%5C%7B0,%201%5C%7D">。</p>
<p>這 <img src="https://latex.codecogs.com/png.latex?n"> 個數據點的聯合機率分佈 (Joint Distribution) 為： <img src="https://latex.codecogs.com/png.latex?%0AP(%5Cmathbf%7BX%7D%20=%20%5Cmathbf%7Bx%7D%20%5Cmid%20%5Ctheta)%0A:=%20P(X_1=x_1,%20X_2=x_2,%20%5Cldots,%20X_n=x_n%20%5Cmid%20%5Ctheta)%0A=%20%5Ctheta%5E%7B%5Csum%20x_i%7D%20(1-%5Ctheta)%5E%7Bn%20-%20%5Csum%20x_i%7D%0A"> 觀察這個式子，你會發現它只依賴於 <img src="https://latex.codecogs.com/png.latex?%5Csum%20x_i">（也就是正面朝上的總次數），而不在乎 <img src="https://latex.codecogs.com/png.latex?0"> 和 <img src="https://latex.codecogs.com/png.latex?1"> 出現的具體順序。</p>
<p>令 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7Bx%7D)%20=%20%5Csum_%7Bi=1%7D%5En%20x_i"> 為統計量。若我們固定 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7Bx%7D)%20=%20%5Cmu">，也就是已知正面出現了 <img src="https://latex.codecogs.com/png.latex?%5Cmu"> 次，那麼原本實驗結果 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bx%7D"> 的條件機率分佈為何？</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0AP(%5Cmathbf%7BX%7D%20=%20%5Cmathbf%7Bx%7D%20%5Cmid%20%5Ctheta,%20T(%5Cmathbf%7BX%7D)%20=%20%5Cmu)%0A&amp;=%20%5Cfrac%7BP(%5Cmathbf%7BX%7D%20=%20%5Cmathbf%7Bx%7D%20%5Cmid%20%5Ctheta)%7D%7BP(T(%5Cmathbf%7BX%7D)%20=%20%5Cmu%20%5Cmid%20%5Ctheta)%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B%5Ctheta%5E%7B%5Cmu%7D%20(1-%5Ctheta)%5E%7Bn%20-%20%5Cmu%7D%7D%7B%5Cbinom%7Bn%7D%7B%5Cmu%7D%20%5Ctheta%5E%7B%5Cmu%7D%20(1-%5Ctheta)%5E%7Bn%20-%20%5Cmu%7D%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Cbinom%7Bn%7D%7B%5Cmu%7D%7D%20%5Cqquad%20%5Ctextbf%7B(%E8%B7%9F%20$%5Ctheta$%20%E7%84%A1%E9%97%9C%EF%BC%81)%7D%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p><strong>注意到最後的結果完全不包含 <img src="https://latex.codecogs.com/png.latex?%5Ctheta">！</strong></p>
<p>這意味著：一旦我們知道正面出現了幾次（<img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)">），具體是「正反正」還是「反正正」出現的機率都是 <img src="https://latex.codecogs.com/png.latex?1/%5Cbinom%7Bn%7D%7B%5Cmu%7D">，這純粹是排列組合問題，與硬幣本身的性質 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 無關。</p>
<p>因此，我們定義：如果滿足下式，則 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 是 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 的 <strong>Sufficient Statistic</strong>： <img src="https://latex.codecogs.com/png.latex?%0AP(%5Cmathbf%7BX%7D%20%5Cmid%20%5Ctheta,%20T(%5Cmathbf%7BX%7D))%20=%20P(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%5Ctag%7B1%7D%5Clabel%7Beq:suff_stat_def%7D%0A"> 換句話說，給定 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 後，原始數據 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D"> 分佈不再依賴於參數 <img src="https://latex.codecogs.com/png.latex?%5Ctheta">。</p>
</section>
<section id="引進-information-theory-的語言" class="level3">
<h3 class="anchored" data-anchor-id="引進-information-theory-的語言">引進 Information Theory 的語言</h3>
<p>消息理論完全是基於機率論的東西，但他所定義的各種概念，似乎捕捉到了甚麼「資訊」的本質。可以從今天這個角度來欣賞一下。</p>
<p>先定義一個隨機變數的資訊熵(Shannon Entropy)，若是離散: <img src="https://latex.codecogs.com/png.latex?%0AH(X)%20=%20-%20%5Csum_%7Bx%7D%20P(X=x)%20%5Clog%20P(X=x)%0A"> 若是連續函數，則改成積分(稱之為 differential entropy，可能取值為負): <img src="https://latex.codecogs.com/png.latex?%0AH(X)%20=%20-%20%5Cint%20f_X(x)%20%5Clog%20f_X(x)%20dx%0A"> 還記得在 <a href="../../posts/normal-distribution/day_1.html#sec-max_entropy">前面文章</a>，已經證明過常態分佈會最大化熵(給定平均值和變異數的限制下)。</p>
<p>接著，mutual information 定義為: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0AI(X;%20Y)%0A&amp;=%20H(X)%20-%20H(X%7CY)%20%20%20%5C%5C%0A&amp;=%20H(Y)%20-%20H(Y%7CX)%20%20%20%5C%5C%0A&amp;=%20H(X)%20+%20H(Y)%20-%20H(X,%20Y)%20%20%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 以上這些定義都是等價的。</p>
<p>如果 <img src="https://latex.codecogs.com/png.latex?X"> 和 <img src="https://latex.codecogs.com/png.latex?Y"> 是獨立的，那麼 <img src="https://latex.codecogs.com/png.latex?H(X%7CY)%20=%20H(X)">，所以 <img src="https://latex.codecogs.com/png.latex?I(X;%20Y)%20=%200">。反過來說，如果 <img src="https://latex.codecogs.com/png.latex?I(X;%20Y)%20=%200">，那麼 <img src="https://latex.codecogs.com/png.latex?X"> 和 <img src="https://latex.codecogs.com/png.latex?Y"> 必須是獨立的。所以 mutual information 衡量了兩個隨機變數與獨立性的差距。</p>
</section>
<section id="sufficient-statistic-的各種等價定義" class="level3">
<h3 class="anchored" data-anchor-id="sufficient-statistic-的各種等價定義">Sufficient Statistic 的各種等價定義</h3>
<p>還記得我們只關心 likelihood function，就是 <img src="https://latex.codecogs.com/png.latex?P(%5Cmathbf%7BX%7D%20%5Cmid%20%5Ctheta)">。</p>
<p>如果說 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 也是隨機變數，那我們就可以開始討論 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 的分布、資訊熵、mutual information 之類的。但這邊的設定 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 只是一個待定的參數，若要討論 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 的分布，那就是開始對 prior distribution 做假設了。而這邊很巧妙的是，我們可以推導出一些性質，是不論 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 的prior是怎樣，都會成立的性質! 所以說</p>
<blockquote class="blockquote">
<p>消息理論假設「有prior」，但不在乎prior是什麼。</p>
</blockquote>
<p>以下假設 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 有個 prior 分布，並假設 <img src="https://latex.codecogs.com/png.latex?T"> 是個 Sufficient Statistic 滿足 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:suff_stat_def%7D">，那麼我們有: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0AP(%5Cmathbf%7BX%7D%20%5Cmid%20%5Ctheta,%20T(%5Cmathbf%7BX%7D))%0A&amp;=%20P(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%20%5Cqquad%20%5Ctext%7B(Sufficient%20Statistic%20%E5%AE%9A%E7%BE%A9)%7D%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 同乘以 <img src="https://latex.codecogs.com/png.latex?P(%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))">， <img src="https://latex.codecogs.com/png.latex?%0AP(%5Cmathbf%7BX%7D,%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%0A=%20P(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20P(%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%20%5Ctag%7B2%7D%5Clabel%7Beq:suff_stat_indep%7D%20%20%20%0A"></p>
<p>這個式子的解讀就是: 給定 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 後，<img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D"> 和 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 是條件獨立的 (conditionally independent)。 一般的推導很可能會直接跳結論:</p>
<blockquote class="blockquote">
<p>Conditioning on <img src="https://latex.codecogs.com/png.latex?T(X)">, <img src="https://latex.codecogs.com/png.latex?X"> and <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> have mutual information equals <img src="https://latex.codecogs.com/png.latex?0">。</p>
</blockquote>
<p>但我想帶大家走一下這段推導。</p>
<p>同時取 <img src="https://latex.codecogs.com/png.latex?%5Clog">: <img src="https://latex.codecogs.com/png.latex?%0A%5Clog%20P(%5Cmathbf%7BX%7D,%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%0A=%20%5Clog%20P(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20+%20%5Clog%20P(%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%0A"> 將上式對 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D,%20%5Ctheta"> 取條件期望值(限制在 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)">): <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A%5Cint%20P(%5Cmathbf%7BX%7D,%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%5Clog%20P(%5Cmathbf%7BX%7D,%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20d%5Cmathbf%7BX%7D%20d%5Ctheta%0A&amp;=%20%5Cint%20P(%5Cmathbf%7BX%7D,%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%5Clog%20P(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20d%5Cmathbf%7BX%7D%20d%5Ctheta%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cint%20P(%5Cmathbf%7BX%7D,%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%5Clog%20P(%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20d%5Cmathbf%7BX%7D%20d%5Ctheta%20%5C%5C%0A&amp;=%20%5Cint%20P(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%5Clog%20P(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20d%5Cmathbf%7BX%7D%20%5C%5C%0A&amp;%5Cquad%20+%20%5Cint%20P(%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%5Clog%20P(%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20d%5Ctheta%20%5C%5C%0A%5Cend%7Baligned%7D%0A"> 所以同乘以 <img src="https://latex.codecogs.com/png.latex?-1">，我們有: <img src="https://latex.codecogs.com/png.latex?%0AH(%5Cmathbf%7BX%7D,%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%0A=%20H(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20+%20H(%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%20%5Ctag%7B3%7D%5Clabel%7Beq:suff_stat_entropy%7D%0A"></p>
<p>這個式子的解讀就是: 給定 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 後，<img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D"> 和 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 的條件熵是可加的 (additive)。</p>
<p>再進一步，這也是 conditional mutual information 的定義: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0AI(%5Cmathbf%7BX%7D;%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%0A&amp;%5Ccoloneqq%20H(%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20+%20H(%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20-%20H(%5Cmathbf%7BX%7D,%20%5Ctheta%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%20%20%5C%5C%0A&amp;=%200%20%20%5Ctag%7B4%7D%5Clabel%7Beq:suff_stat_mutual_info%7D%0A%5Cend%7Balign%7D%0A"></p>
<p>因為這個結構的特殊性 ( <img src="https://latex.codecogs.com/png.latex?%5Ctheta%20%5Crightarrow%20%5Cmathbf%7BX%7D%20%5Crightarrow%20T(%5Cmathbf%7BX%7D)"> 是個馬可夫鏈)，我們本來就會有: <img src="https://latex.codecogs.com/png.latex?%0AI(%5Ctheta;%20T(%5Cmathbf%7BX%7D)%20%5Cmid%20%5Cmathbf%7BX%7D)%20=%200%20%20%5Ctag%7BMarkov-chain%7D%5Clabel%7Beq:markov_chain%7D%0A"> 根據</p>
<blockquote class="blockquote">
<p>Mutual information 的 chain rule: <img src="https://latex.codecogs.com/png.latex?%0AI(X;%20Y,%20Z)%20=%20I(X;%20Z)%20+%20I(X;%20Y%20%5Cmid%20Z)%0A"></p>
</blockquote>
<p><img src="https://latex.codecogs.com/png.latex?%0AI(%5Ctheta;%20T(%5Cmathbf%7BX%7D)%20%5Cmid%20%5Cmathbf%7BX%7D)%20+%20I(%5Ctheta;%20%5Cmathbf%7BX%7D)%0A=%20I(%5Ctheta;%20%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20+%20I(%5Ctheta;%20T(%5Cmathbf%7BX%7D))%0A"> 因為是 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:markov_chain%7D">，所以左邊第一項是 <img src="https://latex.codecogs.com/png.latex?0">，因此我們有: <img src="https://latex.codecogs.com/png.latex?%0AI(%5Ctheta;%20%5Cmathbf%7BX%7D)%20-%20I(%5Ctheta;%20T(%5Cmathbf%7BX%7D))%0A=%20I(%5Ctheta;%20%5Cmathbf%7BX%7D%20%5Cmid%20T(%5Cmathbf%7BX%7D))%20%5Cge%200%20%5Ctag%7BData-Processing%20Inequality%7D%5Clabel%7Beq:data_processing_ineq%7D%0A"> 而等號成立當且僅當 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D"> 和 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 在給定 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 後是條件獨立的，也就是說 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 是個 Sufficient Statistic。</p>
<p>所以如果 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 是個 Sufficient Statistic，那麼 <img src="https://latex.codecogs.com/png.latex?%0AI(%5Ctheta;%20%5Cmathbf%7BX%7D)%20=%20I(%5Ctheta;%20T(%5Cmathbf%7BX%7D))%20%20%5Ctag%7B5%7D%5Clabel%7Beq:suff_stat_info_eq%7D%0A"></p>
<p><strong>綜合以上</strong>: <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:suff_stat_def%7D">、<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:suff_stat_indep%7D">、<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:suff_stat_entropy%7D">、<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:suff_stat_mutual_info%7D">、<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:suff_stat_info_eq%7D">，都是等價的定義。</p>
</section>
<section id="normal-distribution-的-sufficient-statistic-很簡單就是樣本均值和樣本變異數" class="level3">
<h3 class="anchored" data-anchor-id="normal-distribution-的-sufficient-statistic-很簡單就是樣本均值和樣本變異數">Normal Distribution 的 Sufficient Statistic 很簡單，就是樣本均值和樣本變異數:</h3>
<p>假設我們有 <img src="https://latex.codecogs.com/png.latex?X_1,%20X_2,%20%5Cldots,%20X_n"> 是來自常態分佈 <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(%5Cmu,%20%5Csigma%5E2)"> 的 i.i.d. 樣本，則 <img src="https://latex.codecogs.com/png.latex?%5Ctheta%20=%20(%5Cmu,%20%5Csigma%5E2)"> 的 Sufficient Statistic 就是樣本均值和樣本變異數: <img src="https://latex.codecogs.com/png.latex?%0AT(%5Cmathbf%7BX%7D)%20=%20%5Cleft(%20%5Cbar%7BX%7D,%20S%5E2%20%5Cright)%20=%20%5Cleft(%20%5Cfrac%7B1%7D%7Bn%7D%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20X_i,%20%5Cfrac%7B1%7D%7Bn-1%7D%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cbar%7BX%7D)%5E2%20%5Cright)%0A"> 也就是說，給定樣本均值和樣本變異數後，原本的樣本數據對於 <img src="https://latex.codecogs.com/png.latex?%5Cmu,%20%5Csigma%5E2"> 不再提供任何額外資訊。</p>
<p>為什麼哩? 因為常態分佈的 likelihood function 只依賴於樣本均值和樣本變異數: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0AP(%5Cmathbf%7BX%7D%20%5Cmid%20%5Cmu,%20%5Csigma%5E2)%0A&amp;=%20%5Cprod_%7Bi=1%7D%5E%7Bn%7D%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%20%5Cpi%20%5Csigma%5E2%7D%7D%20%5Cexp%5Cleft(%20-%5Cfrac%7B(X_i%20-%20%5Cmu)%5E2%7D%7B2%20%5Csigma%5E2%7D%20%5Cright)%20%20%5C%5C%0A&amp;=%20%5Cleft(%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%20%5Cpi%20%5Csigma%5E2%7D%7D%20%5Cright)%5En%20%5Cexp%5Cleft(%20-%5Cfrac%7B1%7D%7B2%20%5Csigma%5E2%7D%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cmu)%5E2%20%5Cright)%20%5C%5C%0A&amp;=%20%5Cleft(%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%20%5Cpi%20%5Csigma%5E2%7D%7D%20%5Cright)%5En%20%5Cexp%5Cleft(%20-%5Cfrac%7B1%7D%7B2%20%5Csigma%5E2%7D%20%5Cleft%5B%20(n-1)%20S%5E2%20+%20n%20(%5Cbar%7BX%7D%20-%20%5Cmu)%5E2%20%5Cright%5D%20%5Cright)%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>直觀上來說，這個 likelihood function 跟 <img src="https://latex.codecogs.com/png.latex?X"> 有關的部分只剩下 <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BX%7D"> 和 <img src="https://latex.codecogs.com/png.latex?S%5E2">，所以這兩個統計量已經「充分」地捕捉了關於 <img src="https://latex.codecogs.com/png.latex?%5Cmu"> 和 <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"> 的所有資訊。</p>
<p>但根據定義 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:suff_stat_def%7D">，我們需要計算 <img src="https://latex.codecogs.com/png.latex?P(%5Cmathbf%7BX%7D%20%5Cmid%20%5Cmu,%20%5Csigma%5E2,%20T(%5Cmathbf%7BX%7D))">，並驗證它不依賴於 <img src="https://latex.codecogs.com/png.latex?%5Cmu"> 和 <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2">。</p>
<p>嘿! 但這裡出現了小麻煩，因為是連續的機率密函數，所以不知道怎麼處理 OAO (請參見: 硬核系列-測度論)。</p>
</section>
<section id="直覺是對的-fisher-neyman-factorization-theorem" class="level3">
<h3 class="anchored" data-anchor-id="直覺是對的-fisher-neyman-factorization-theorem">直覺是對的: Fisher-Neyman Factorization Theorem</h3>
<p>我們直觀上覺得應該可以從 likelihood function 看出來 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 是 Sufficient Statistic。這也就是以下定理:</p>
<blockquote class="blockquote">
<p><strong>(Fisher-Neyman Factorization Theorem)</strong> 若 <img src="https://latex.codecogs.com/png.latex?X_1,%20%5Cldots,%20X_n"> 的聯合機率密度函數 (joint pdf/pmf) 為 <img src="https://latex.codecogs.com/png.latex?f(%5Cmathbf%7Bx%7D%20%5Cmid%20%5Ctheta)">。則 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7BX%7D)"> 是 <img src="https://latex.codecogs.com/png.latex?%5Ctheta"> 的 Sufficient Statistic 若且唯若 存在兩個非負函數 <img src="https://latex.codecogs.com/png.latex?g"> 和 <img src="https://latex.codecogs.com/png.latex?h">，使得： <img src="https://latex.codecogs.com/png.latex?%0Af(%5Cmathbf%7Bx%7D%20%5Cmid%20%5Ctheta)%20=%20g(T(%5Cmathbf%7Bx%7D),%20%5Ctheta)%20%5Ccdot%20h(%5Cmathbf%7Bx%7D)%0A"></p>
<ul>
<li><p><img src="https://latex.codecogs.com/png.latex?g(T(%5Cmathbf%7Bx%7D),%20%5Ctheta)">：這部分包含了 <img src="https://latex.codecogs.com/png.latex?%5Ctheta">，但它只透過 <img src="https://latex.codecogs.com/png.latex?T(%5Cmathbf%7Bx%7D)"> 來依賴數據 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bx%7D">。</p></li>
<li><p><img src="https://latex.codecogs.com/png.latex?h(%5Cmathbf%7Bx%7D)">：這部分可以依賴所有的數據 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bx%7D">，但絕對不能包含 <img src="https://latex.codecogs.com/png.latex?%5Ctheta">。</p></li>
</ul>
</blockquote>


</section>

 ]]></description>
  <category>Normal Distribution</category>
  <guid>https://your-website-url.example.com/posts/normal-distribution/day_4.html</guid>
  <pubDate>Sun, 16 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>最短的向量</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/2025-1116-shortest_vector/index.html</link>
  <description><![CDATA[ 




<section id="從無窮多組解中找一組最小的" class="level1">
<h1>從無窮多組解中，找一組最小的</h1>
<p>假設在 <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BR%7D%5En"> 空間中有 <img src="https://latex.codecogs.com/png.latex?n"> 個向量 <img src="https://latex.codecogs.com/png.latex?v_1,%20...,%20v_n">，要找他們的整係數線性組合，使得其長度最小(但非零)。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Barray%7D%7Bcl%7D%0A%5Cmin%20&amp;%20%5CBig%5C%7C%20v%20%5CBig%5C%7C_2%20%5C%5C%0A%5Ctext%7Bs.t.%7D%20&amp;%20v%20=%20%5Csum_%7Bi=1%7D%5En%20a_i%20v_i,%20%5Cquad%20a_i%20%5Cin%20%5Cmathbb%7BZ%7D,%20%5Cquad%20v%20%5Cneq%200%0A%5Cend%7Barray%7D%0A"></p>
<p>也可以考慮個整數版本的，但向量的個數要比 <img src="https://latex.codecogs.com/png.latex?n"> 多一些。假設 <img src="https://latex.codecogs.com/png.latex?v_1,%20...,%20v_m"> 是 <img src="https://latex.codecogs.com/png.latex?%5Cmathbb%7BZ%7D_q%5En"> 中的 <img src="https://latex.codecogs.com/png.latex?m"> 個向量。</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Barray%7D%7Bcl%7D%0A%5Cmin%20&amp;%20%5Csum_%7Bi=1%7D%5Em%20a_i%5E2%20%5C%5C%0A%5Ctext%7Bs.t.%7D%20&amp;%20%5Csum_%7Bi=1%7D%5Em%20a_i%20v_i%20%5Cequiv%200%20(mod%20q),%20%5Cquad%20a_i%20%5Cin%20%5Cmathbb%7BZ%7D,%20%5Cexists%20a_i%20%5Cneq%200%0A%5Cend%7Barray%7D%0A"></p>
<p>在這個情形中，我們反過來是要求向量合為零時，最小的係數是多少。</p>


</section>

 ]]></description>
  <category>Cryptography</category>
  <category>NP-Reduction</category>
  <category>Linear Algebra</category>
  <guid>https://your-website-url.example.com/posts/2025-1116-shortest_vector/index.html</guid>
  <pubDate>Sat, 15 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>10 Types of Common Distributions</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/2025-1114-distribution_10/index.html</link>
  <description><![CDATA[ 




<p>Let’s list 10 common continuous probability distributions along with their probability density functions (PDFs), I’ve ignored the constant normalization factors for simplicity. Here’s a summary table:</p>
<section id="continuous-probability-distributions-table" class="level3">
<h3 class="anchored" data-anchor-id="continuous-probability-distributions-table">Continuous Probability Distributions Table</h3>
<div id="tbl-simple" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-simple-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;1: My Distribution Table
</figcaption>
<div aria-describedby="tbl-simple-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="caption-top table">
<colgroup>
<col style="width: 13%">
<col style="width: 13%">
<col style="width: 13%">
<col style="width: 15%">
<col style="width: 15%">
<col style="width: 13%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">CF</th>
<th style="text-align: left;">Name, Notation</th>
<th style="text-align: center;">Parameters</th>
<th style="text-align: center;">PDF</th>
<th style="text-align: center;">Range</th>
<th style="text-align: center;">Mean</th>
<th style="text-align: center;">Variance</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?e%5E%7Bi%5Cmu%20t%20-%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D"></td>
<td style="text-align: left;"><strong>Normal</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(%5Cmu,%20%5Csigma%5E2)"></td>
<td style="text-align: center;">mean: <img src="https://latex.codecogs.com/png.latex?%5Cmu"> <br> variance: <img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20e%5E%7B-%5Cfrac%7B1%7D%7B2%5Csigma%5E2%7Dx%5E2+%5Cfrac%7B%5Cmu%7D%7B%5Csigma%5E2%7Dx%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%20%5Cin%20(-%5Cinfty,%20%5Cinfty)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cmu"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?(1%20-%202it)%5E%7B-%5Cfrac%7Bk%7D%7B2%7D%7D"></td>
<td style="text-align: left;"><strong>Chi-Squared</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2(k)"></td>
<td style="text-align: center;">degree of freedom (d.o.f): <img src="https://latex.codecogs.com/png.latex?k"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20x%5E%7B%5Cfrac%7Bk%7D%7B2%7D-1%7De%5E%7B-%5Cfrac%7Bx%7D%7B2%7D%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(0,%20%5Cinfty)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?k"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?2k"></td>
</tr>
<tr class="odd">
<td style="text-align: left;">ugly</td>
<td style="text-align: left;"><strong>Chi [Optional]</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cchi(k)"></td>
<td style="text-align: center;">degree of freedom (d.o.f): <img src="https://latex.codecogs.com/png.latex?k"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20x%5E%7Bk-1%7De%5E%7B-%5Cfrac%7Bx%5E2%7D%7B2%7D%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(0,%20%5Cinfty)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Csqrt%7B2%7D%20%5Cfrac%7B%5CGamma(%5Cfrac%7Bk+1%7D%7B2%7D)%7D%7B%5CGamma(%5Cfrac%7Bk%7D%7B2%7D)%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?k%20-%20%5Cleft(%5Csqrt%7B2%7D%20%5Cfrac%7B%5CGamma(%5Cfrac%7Bk+1%7D%7B2%7D)%7D%7B%5CGamma(%5Cfrac%7Bk%7D%7B2%7D)%7D%5Cright)%5E2"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Clambda%7D%7B%5Clambda%20-%20it%7D"></td>
<td style="text-align: left;"><strong>Exponential</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BExp%7D(%5Clambda)"></td>
<td style="text-align: center;">rate: <img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20e%5E%7B-%5Clambda%20x%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(0,%20%5Cinfty)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B%5Clambda%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B%5Clambda%5E2%7D"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?%5Cleft(1%20-%20i%5Ctheta%20t%5Cright)%5E%7B-%5Calpha%7D"></td>
<td style="text-align: left;"><strong>Gamma</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BGamma%7D(%5Calpha,%20%5Ctheta)"></td>
<td style="text-align: center;">shape: <img src="https://latex.codecogs.com/png.latex?%5Calpha"> <br> scale: <img src="https://latex.codecogs.com/png.latex?%5Ctheta"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20x%5E%7B%5Calpha-1%7D%20e%5E%7B-%5Cfrac%7Bx%7D%7B%5Ctheta%7D%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(0,%20%5Cinfty)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Calpha%5Ctheta"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Calpha%5Ctheta%5E2"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?%7B%7D_1F_1(%5Calpha;%20%5Calpha+%5Cbeta;%20it)"></td>
<td style="text-align: left;"><strong>Beta</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BBeta%7D(%5Calpha,%20%5Cbeta)"></td>
<td style="text-align: center;">shape1: <img src="https://latex.codecogs.com/png.latex?%5Calpha"> <br> shape2: <img src="https://latex.codecogs.com/png.latex?%5Cbeta"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20x%5E%7B%5Calpha-1%7D(1-x)%5E%7B%5Cbeta-1%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(0,%201)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Calpha%7D%7B%5Calpha+%5Cbeta%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Calpha%5Cbeta%7D%7B(%5Calpha+%5Cbeta)%5E2(%5Calpha+%5Cbeta+1)%7D"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Csin(t)%7D%7Bt%7D"></td>
<td style="text-align: left;"><strong>Uniform</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BUniform%7D(-1,%201)"></td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Ctext%7Bconstant%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(-1,%201)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?0"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1%7D%7B3%7D"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?e%5E%7B-%7Ct%7C%7D"></td>
<td style="text-align: left;"><strong>Cauchy</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BCauchy%7D"></td>
<td style="text-align: center;">NA</td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cfrac%7B1%7D%7B1+x%5E2%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(-%5Cinfty,%20%5Cinfty)"></td>
<td style="text-align: center;">undefined</td>
<td style="text-align: center;">undefined</td>
</tr>
<tr class="odd">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7BK_%7B%5Cfrac%7B%5Cnu%7D%7B2%7D%7D(%5Csqrt%7B%5Cnu%7D%7Ct%7C)%20(%5Csqrt%7B%5Cnu%7D%7Ct%7C)%5E%7B%5Cfrac%7B%5Cnu%7D%7B2%7D%7D%7D%7B%5CGamma(%5Cfrac%7B%5Cnu%7D%7B2%7D)%202%5E%7B%5Cfrac%7B%5Cnu%7D%7B2%7D-1%7D%7D"></td>
<td style="text-align: left;"><strong>Student’s t</strong> <br> <img src="https://latex.codecogs.com/png.latex?t(%5Cnu)"></td>
<td style="text-align: center;">dof: <img src="https://latex.codecogs.com/png.latex?%5Cnu"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cleft(1+%5Cfrac%7Bx%5E2%7D%7B%5Cnu%7D%5Cright)%5E%7B-%5Cfrac%7B%5Cnu+1%7D%7B2%7D%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(-%5Cinfty,%20%5Cinfty)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?0"> for <img src="https://latex.codecogs.com/png.latex?%5Cnu%3E1"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B%5Cnu%7D%7B%5Cnu-2%7D">, for <img src="https://latex.codecogs.com/png.latex?%5Cnu%3E2"></td>
</tr>
<tr class="even">
<td style="text-align: left;">ugly</td>
<td style="text-align: left;"><strong>F-distribution</strong> <br> <img src="https://latex.codecogs.com/png.latex?F(d_1,%20d_2)"></td>
<td style="text-align: center;">dof 1: <img src="https://latex.codecogs.com/png.latex?d_1"> <br> dof 2: <img src="https://latex.codecogs.com/png.latex?d_2"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cleft(%5Cfrac%7Bd_1%20x%7D%7Bd_1%20x%20+%20d_2%7D%5Cright)%5E%7B%5Cfrac%7Bd_1%7D%7B2%7D%7D%20%5Cleft(%5Cfrac%7Bd_2%7D%7Bd_1%20x%20+%20d_2%7D%5Cright)%5E%7B%5Cfrac%7Bd_2%7D%7B2%7D%7D%20x%5E%7B-1%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin(0,%20%5Cinfty)"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Bd_2%7D%7Bd_2%20-%202%7D">, for <img src="https://latex.codecogs.com/png.latex?d_2"> &gt;2</td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B2%20d_2%5E2%20(d_1%20+%20d_2%20-%202)%7D%7Bd_1%20(d_2%20-%202)%5E2%20(d_2%20-%204)%7D">, for <img src="https://latex.codecogs.com/png.latex?d_2"> &gt;4</td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?%7B%5Cdisplaystyle%20K_%7B%5Cnu%20%7D%7D"> is the <a href="https://en.wikipedia.org/wiki/Bessel_function#Modified_Bessel_functions:_I%CE%B1,_K%CE%B1">modified Bessel function of the second kind</a>.</li>
<li><img src="https://latex.codecogs.com/png.latex?%7B%7D_1F_1(a;%20b;%20z)"> is the <a href="https://en.wikipedia.org/wiki/Confluent_hypergeometric_function">confluent hypergeometric function</a>.</li>
</ul>
</section>
<section id="discrete-distributions" class="level3">
<h3 class="anchored" data-anchor-id="discrete-distributions">Discrete Distributions</h3>
<p>Here are lists for common discrete probability distributions:</p>
<div id="tbl-discrete" class="quarto-float quarto-figure quarto-figure-center anchored">
<figure class="quarto-float quarto-float-tbl figure">
<figcaption class="quarto-float-caption-top quarto-float-caption quarto-float-tbl" id="tbl-discrete-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
Table&nbsp;2: My Discrete Distribution Table
</figcaption>
<div aria-describedby="tbl-discrete-caption-0ceaefa1-69ba-4598-a22c-09a6ac19f8ca">
<table class="caption-top table">
<colgroup>
<col style="width: 13%">
<col style="width: 13%">
<col style="width: 13%">
<col style="width: 15%">
<col style="width: 13%">
<col style="width: 13%">
<col style="width: 15%">
</colgroup>
<thead>
<tr class="header">
<th style="text-align: left;">CF</th>
<th style="text-align: left;">Name, Notation</th>
<th style="text-align: center;">Parameters</th>
<th style="text-align: center;">PMF</th>
<th style="text-align: center;">Range</th>
<th style="text-align: center;">Mean</th>
<th style="text-align: center;">Variance</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?1%20-%20p%20+%20p%20e%5E%7Bit%7D"></td>
<td style="text-align: left;"><strong>Bernoulli</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BBernoulli%7D(p)"></td>
<td style="text-align: center;">success prob.: <img src="https://latex.codecogs.com/png.latex?p"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20p%5Ex%20(1-p)%5E%7B1-x%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin%5C%7B0,1%5C%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?p"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?p(1-p)"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?(1%20-%20p%20+%20p%20e%5E%7Bit%7D)%5En"></td>
<td style="text-align: left;"><strong>Binomial</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BBinomial%7D(n,%20p)"></td>
<td style="text-align: center;">trials: <img src="https://latex.codecogs.com/png.latex?n"> <br> success prob.: <img src="https://latex.codecogs.com/png.latex?p"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cbinom%7Bn%7D%7Bx%7D%20p%5Ex%20(1-p)%5E%7Bn-x%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin%5C%7B0,1,%5Cldots,n%5C%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?np"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?np(1-p)"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?e%5E%7B%5Clambda(e%5E%7Bit%7D-1)%7D"></td>
<td style="text-align: left;"><strong>Poisson</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BPoisson%7D(%5Clambda)"></td>
<td style="text-align: center;">rate: <img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cfrac%7B%5Clambda%5Ex%20e%5E%7B-%5Clambda%7D%7D%7Bx!%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin%5C%7B0,1,2,%5Cldots%5C%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Clambda"></td>
</tr>
<tr class="even">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Bp%20e%5E%7Bit%7D%7D%7B1%20-%20(1-p)e%5E%7Bit%7D%7D"></td>
<td style="text-align: left;"><strong>Geometric</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BGeometric%7D(p)"></td>
<td style="text-align: center;">success prob.: <img src="https://latex.codecogs.com/png.latex?p"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20(1-p)%5E%7Bx%7D%20p"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin%5C%7B0,1,2,%5Cldots%5C%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1-p%7D%7Bp%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7B1-p%7D%7Bp%5E2%7D"></td>
</tr>
<tr class="odd">
<td style="text-align: left;"><img src="https://latex.codecogs.com/png.latex?%5Cleft(%5Cfrac%7Bp%20e%5E%7Bit%7D%7D%7B1%20-%20(1-p)e%5E%7Bit%7D%7D%5Cright)%5Er"></td>
<td style="text-align: left;"><strong>Negative Binomial</strong> <br> <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BNegBin%7D(r,%20p)"></td>
<td style="text-align: center;">successes: <img src="https://latex.codecogs.com/png.latex?r"> <br> success prob.: <img src="https://latex.codecogs.com/png.latex?p"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cbinom%7Bx+r-1%7D%7Br-1%7D%20p%5Er%20(1-p)%5Ex"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?x%5Cin%5C%7B0,1,2,%5Cldots%5C%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Br(1-p)%7D%7Bp%7D"></td>
<td style="text-align: center;"><img src="https://latex.codecogs.com/png.latex?%5Cfrac%7Br(1-p)%7D%7Bp%5E2%7D"></td>
</tr>
</tbody>
</table>
</div>
</figure>
</div>
<hr>
</section>
<section id="relationships" class="level3">
<h3 class="anchored" data-anchor-id="relationships">Relationships</h3>
<p><strong>Obvious</strong>:</p>
<ul>
<li>Exponential is a special case of Gamma: <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BExp%7D(%5Clambda)%20%5Csim%20%5Cmathrm%7BGamma%7D(1,%20%5Cfrac%7B1%7D%7B%5Clambda%7D)">.</li>
<li>Chi-squared is a special case of Gamma: <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2(k)%20%5Csim%20%5Cmathrm%7BGamma%7D(%5Cfrac%7Bk%7D%7B2%7D,%202)">.</li>
<li>A special case of Chi-squared is Exponential: <img src="https://latex.codecogs.com/png.latex?%5Cchi%5E2(2)%20%5Csim%20%5Cmathrm%7BExp%7D(%5Cfrac%7B1%7D%7B2%7D)">. This is called the <em>Rayleigh distribution</em>.</li>
<li>Chi is the square root of Chi-squared: <img src="https://latex.codecogs.com/png.latex?%5Cchi(k)%20%5Csim%20%5Csqrt%7B%5Cchi%5E2(k)%7D">.</li>
<li>Normal is a special case of Chi: <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(0,%201)%20%5Csim%20%5Cchi(1)">.</li>
<li>Cauchy is a special case of Student’s t: <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BCauchy%7D%20%5Csim%20t(1)">.</li>
<li>The chi-squared, Student’s t, and F distributions are all naturally come from the Normal distribution in the following senses:
<ul>
<li><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cchi%5E2(k)%20%5Csim%20%5Csum_%7Bi=1%7D%5Ek%20Z_i%5E2">, where <img src="https://latex.codecogs.com/png.latex?Z_i"> are i.i.d. standard normal variables.</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20t(%5Cnu)%20%5Csim%20%5Cfrac%7BZ%7D%7B%5Csqrt%7B%5Cchi%5E2(%5Cnu)/%5Cnu%7D%7D">, where <img src="https://latex.codecogs.com/png.latex?Z"> is a standard normal variable independent of the Chi-squared variable.</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20F(d_1,%20d_2)%20%5Csim%20%5Cfrac%7B%5Cchi%5E2(d_1)/d_1%7D%7B%5Cchi%5E2(d_2)/d_2%7D">, which is the ratio of two scaled Chi-squared distributions.</li>
</ul></li>
<li>Bernoulli is a special case of Binomial: <img src="https://latex.codecogs.com/png.latex?%5Cmathrm%7BBernoulli%7D(p)%20%5Csim%20%5Cmathrm%7BBinomial%7D(1,%20p)">.</li>
</ul>
<p><strong>Stability</strong>:</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cmathcal%7BN%7D(%5Cmu_1,%20%5Csigma_1%5E2)%20+%20%5Cmathcal%7BN%7D(%5Cmu_2,%20%5Csigma_2%5E2)%20%5Csim%20%5Cmathcal%7BN%7D(%5Cmu_1%20+%20%5Cmu_2,%20%5Csigma_1%5E2%20+%20%5Csigma_2%5E2)">.</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cmathrm%7BGamma%7D(%5Calpha_1,%20%5Ctheta)%20+%20%5Cmathrm%7BGamma%7D(%5Calpha_2,%20%5Ctheta)%20%5Csim%20%5Cmathrm%7BGamma%7D(%5Calpha_1%20+%20%5Calpha_2,%20%5Ctheta)">.</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cchi%5E2(k_1)%20+%20%5Cchi%5E2(k_2)%20%5Csim%20%5Cchi%5E2(k_1%20+%20k_2)">.</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cmathrm%7BBinomial%7D(n_1,%20p)%20+%20%5Cmathrm%7BBinomial%7D(n_2,%20p)%20%5Csim%20%5Cmathrm%7BBinomial%7D(n_1%20+%20n_2,%20p)">.</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Cdisplaystyle%20%5Cmathrm%7BPoisson%7D(%5Clambda_1)%20+%20%5Cmathrm%7BPoisson%7D(%5Clambda_2)%20%5Csim%20%5Cmathrm%7BPoisson%7D(%5Clambda_1%20+%20%5Clambda_2)">.</li>
</ul>
<p><strong>Less Obvious</strong>:</p>
<ul>
<li>Beta is related to Gamma in the following way: <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Bcases%7D%0AX%20%5Csim%20%5Cmathrm%7BGamma%7D(%5Calpha,%20%5Ctheta),%20%20%5C%5C%0AY%20%5Csim%20%5Cmathrm%7BGamma%7D(%5Cbeta,%20%5Ctheta),%20%20%5C%5C%0AX%20%5Cperp%20Y%0A%5Cend%7Bcases%7D%0A%5Cimplies%0A%5Cbegin%7Bcases%7D%0A%5Cdisplaystyle%20%5Cfrac%7BX%7D%7BX+Y%7D%20%5Csim%20%5Cmathrm%7BBeta%7D(%5Calpha,%20%5Cbeta),%20%20%5C%5C%0AX+Y%20%5Csim%20%5Cmathrm%7BGamma%7D(%5Calpha%20+%20%5Cbeta,%20%5Ctheta),%20%5C%5C%0A%5Cdisplaystyle%20%5Cfrac%7BX%7D%7BX+Y%7D%20%5Cperp%20(X+Y)%0A%5Cend%7Bcases%7D%0A">
<ul>
<li>A special case of the above is that taking <img src="https://latex.codecogs.com/png.latex?n"> independent standard normal <img src="https://latex.codecogs.com/png.latex?Z_i%20%5Csim%20%5Cmathcal%7BN%7D(0,1)"> variables, then for any <img src="https://latex.codecogs.com/png.latex?k%20%3C%20n">: <img src="https://latex.codecogs.com/png.latex?%0A%5Cdisplaystyle%20%5Cfrac%7BZ_1%5E2%20+%20Z_2%5E2%20+%20%5Ccdots%20+%20Z_k%5E2%7D%7BZ_1%5E2%20+%20Z_2%5E2%20+%20%5Ccdots%20+%20Z_n%5E2%7D%20%5Csim%20%5Cmathrm%7BBeta%7D%5Cleft(%5Cfrac%7Bk%7D%7B2%7D,%20%5Cfrac%7Bn-k%7D%7B2%7D%5Cright)%0A"> Notice that comparing to the F-distribution, the numerator is using Chi-squared variable from the denominator.</li>
</ul></li>
<li>Sample <img src="https://latex.codecogs.com/png.latex?n"> independent <img src="https://latex.codecogs.com/png.latex?U_i%20%5Csim%20%5Cmathrm%7BUniform%7D(0,1)"> variables. The <img src="https://latex.codecogs.com/png.latex?k">-th order statistic follows a Beta distribution: <img src="https://latex.codecogs.com/png.latex?X_%7B(k)%7D%20%5Csim%20%5Cmathrm%7BBeta%7D(k,%20n-k+1)">.</li>
</ul>
<hr>
<p>(To be added)</p>
<ul>
<li>Exponential is related to Poisson process:
<ul>
<li>If events occur according to a Poisson process with rate <img src="https://latex.codecogs.com/png.latex?%5Clambda">, then the waiting time until the <img src="https://latex.codecogs.com/png.latex?k">-th event follows a Gamma distribution: <img src="https://latex.codecogs.com/png.latex?T_k%20%5Csim%20%5Cmathrm%7BGamma%7D(k,%20%5Cfrac%7B1%7D%7B%5Clambda%7D)">.</li>
<li>The Exponential and Gamma distributions are related to the Poisson process, which models the occurrence of random events over time.</li>
</ul></li>
</ul>
<p>The Beta distribution is often used in Bayesian statistics as a prior distribution for probabilities.</p>


</section>

 ]]></description>
  <category>statistic</category>
  <category>Cheat Sheet</category>
  <guid>https://your-website-url.example.com/posts/2025-1114-distribution_10/index.html</guid>
  <pubDate>Thu, 13 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>一天證明一個 Normal Distribution 的性質 Day3：多變量常態分佈</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/normal-distribution/day_3.html</link>
  <description><![CDATA[ 




<p>今天來講 <img src="https://latex.codecogs.com/png.latex?n"> 維空間的多變量常態分佈 (Multivariate Normal Distribution)。高維空間的常態分佈雖然在形式上只是把一維的做 <img src="https://latex.codecogs.com/png.latex?n"> 次方，但他豐富的特性，卻讓它在統計學、機器學習，甚至於密碼學、純數學理論中都有非常重要的應用。</p>
<p>對一個 <img src="https://latex.codecogs.com/png.latex?n"> 維隨機向量 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D%20=%20(X_1,%20X_2,%20%5Cldots,%20X_n)%5ET">，我們說它服從多變量常態分佈，記作 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D%20%5Csim%20%5Cmathcal%7BN%7D_n(%5Cboldsymbol%7B%5Cmu%7D,%20%5CSigma)">，如果它的機率密度函數 (PDF) 為： <img src="https://latex.codecogs.com/png.latex?%0Af_%7B%5Cmathbf%7BX%7D%7D(%5Cmathbf%7Bx%7D)%20=%20%5Cfrac%7B1%7D%7B(2%5Cpi)%5E%7Bn/2%7D%20%7C%5CSigma%7C%5E%7B1/2%7D%7D%20%5Cexp%5Cleft(%20-%5Cfrac%7B1%7D%7B2%7D%20(%5Cmathbf%7Bx%7D%20-%20%5Cboldsymbol%7B%5Cmu%7D)%5ET%20%5CSigma%5E%7B-1%7D%20(%5Cmathbf%7Bx%7D%20-%20%5Cboldsymbol%7B%5Cmu%7D)%20%5Cright)%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?%5Cboldsymbol%7B%5Cmu%7D%20%5Cin%20%5Cmathbb%7BR%7D%5En"> 是均值向量 (mean vector)，<img src="https://latex.codecogs.com/png.latex?%5CSigma%20%5Cin%20%5Cmathbb%7BR%7D%5E%7Bn%20%5Ctimes%20n%7D"> 是協方差矩陣 (covariance matrix)，且必須是正定矩陣 (positive definite matrix)。</p>
<p>OK，老實說這個公式看起來有點嚇人，但其實我們知道所有對稱的實數正定矩陣都可以被對角化 (diagonalized)，寫成 <img src="https://latex.codecogs.com/png.latex?%5CSigma%20=%20P%20D%20P%5E%7B-1%7D">，所以經過一個 orthogonal 轉換 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D=P%5Cmathbf%7BY%7D">，<img src="https://latex.codecogs.com/png.latex?f_%5Cmathbf%7BX%7D(x)"> 可以寫成 <img src="https://latex.codecogs.com/png.latex?%0Af_%7B%5Cmathbf%7BX%7D%7D(%5Cmathbf%7Bx%7D)%20=%20f_%7B%5Cmathbf%7BY%7D%7D(%5Cmathbf%7By%7D)%20=%20%5Cprod_%7Bi=1%7D%5E%7Bn%7D%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%20%5Csigma_i%5E2%7D%7D%20%5Cexp%5Cleft(%20-%5Cfrac%7B(y_i%20-%20%5Cmu_i)%5E2%7D%7B2%5Csigma_i%5E2%7D%20%5Cright)%0A"> 噹噹! 其實就是 <img src="https://latex.codecogs.com/png.latex?n"> 個獨立的一維常態分佈的乘積啦！</p>
<p><strong>新手常犯的錯誤</strong>：</p>
<ul>
<li>請注意這邊的用詞，我們刻意區分「多變量常態分佈 (Multivariate Normal Distribution)」和 「常態分佈(Normal Distribution)」。</li>
<li>隨機變數 <img src="https://latex.codecogs.com/png.latex?X,%20Y"> 都是常態分佈，並 <strong>不代表</strong> <img src="https://latex.codecogs.com/png.latex?(X,%20Y)"> 這個二維向量服從多變量常態分佈，除非 <img src="https://latex.codecogs.com/png.latex?X"> 和 <img src="https://latex.codecogs.com/png.latex?Y"> 是獨立的 (independent)！這點非常重要。獨立是個很強的條件， <img src="https://latex.codecogs.com/png.latex?(X,%20Y)"> 的聯合分佈 (joint distribution) 可能會有非常複雜的形式。</li>
<li>如果隨機變數 <img src="https://latex.codecogs.com/png.latex?(X,%20Y)"> 服從二維多變量常態分佈，而且 covariance 為 <img src="https://latex.codecogs.com/png.latex?0"> ，那麼 <img src="https://latex.codecogs.com/png.latex?X"> 和 <img src="https://latex.codecogs.com/png.latex?Y"> 一定是獨立的！這是個簡單推論，但卻是多變量常態分佈的一個非常特別的性質，其他分佈並不一定成立。</li>
<li><strong>Kac-Berstein Theorem [Optional]</strong>。事實上，我們只需要假設 <img src="https://latex.codecogs.com/png.latex?X"> 和 <img src="https://latex.codecogs.com/png.latex?Y"> 是獨立的隨機變數(一維)，且 <img src="https://latex.codecogs.com/png.latex?X-Y"> 和 <img src="https://latex.codecogs.com/png.latex?X+Y"> 也是獨立的，那麼 <img src="https://latex.codecogs.com/png.latex?(X,%20Y)"> 必須服從二維的多變量常態分佈。(WHY?)</li>
<li><strong>Cramer’s decomposition Theorem [Optional]</strong>。如果 <img src="https://latex.codecogs.com/png.latex?X"> 和 <img src="https://latex.codecogs.com/png.latex?Y"> 是獨立的隨機變數，且 <img src="https://latex.codecogs.com/png.latex?X+Y"> 服從常態分佈，那麼 <img src="https://latex.codecogs.com/png.latex?X"> 和 <img src="https://latex.codecogs.com/png.latex?Y"> 必須服從常態分佈。(WHY?)</li>
</ul>
<section id="旋轉不變性-rotational-invariance" class="level3">
<h3 class="anchored" data-anchor-id="旋轉不變性-rotational-invariance">旋轉不變性 (Rotational Invariance)</h3>
<p>如果我們取標準的多變量常態分佈 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D%20%5Csim%20%5Cmathcal%7BN%7D_n(%5Cmathbf%7B0%7D,%20I_n)">，其中 <img src="https://latex.codecogs.com/png.latex?I_n"> 是 <img src="https://latex.codecogs.com/png.latex?n"> 維單位矩陣 (identity matrix)。那對於任意的正交矩陣 (orthogonal matrix) <img src="https://latex.codecogs.com/png.latex?Q">（即 <img src="https://latex.codecogs.com/png.latex?Q%5ET%20Q%20=%20I_n">），我們有: <img src="https://latex.codecogs.com/png.latex?%20%20%0A%5Cmathbf%7BY%7D%20=%20Q%20%5Cmathbf%7BX%7D%20%5Csim%20%5Cmathcal%7BN%7D_n(%5Cmathbf%7B0%7D,%20I_n)%20%5Cquad%20%5Ctag%7B1%7D%5Clabel%7Beq:rotate_invar%7D%0A"> 這是因為 <img src="https://latex.codecogs.com/png.latex?f_%7B%5Cmathbf%7BX%7D%7D(%5Cmathbf%7Bx%7D)%20%5Cpropto%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D%20%5Cmathbf%7Bx%7D%5ET%20%5Cmathbf%7Bx%7D%7D">，而 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7Bx%7D%5ET%20%5Cmathbf%7Bx%7D"> 在正交變換下是不變的。</p>
<p>而對於一般的多變量常態分佈 <img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D%20%5Csim%20%5Cmathcal%7BN%7D_n(%5Cboldsymbol%7B%5Cmu%7D,%20%5Csigma%5E2%5Cmathbf%7BI%7D_n)">，我們需要做個平移: <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%7BY%7D%20=%20Q(%5Cmathbf%7BX%7D%20-%20%5Cmathbf%7B%5Cmu%7D)%20%5Csim%20%5Cmathcal%7BN%7D_n(%5Cboldsymbol%7B0%7D,%20%5Csigma%5E2%20I_n)%20%20%5Ctag%7B2%7D%5Clabel%7Beq:rotate_invar_shift%7D%0A"></p>
<p>這其實是個非常奇妙的性質，以至於只有常態分佈才有這個特性。</p>
<p><strong>從最直覺的觀點: PDF 函數</strong></p>
<p>假設一個在 <img src="https://latex.codecogs.com/png.latex?n"> 維空間中的PDF函數 <img src="https://latex.codecogs.com/png.latex?f_%5Cmathbf%7BX%7D(x)"> 具有旋轉不變性，同時又是 <img src="https://latex.codecogs.com/png.latex?n"> 個一維獨立變數的乘積。那首先，這些一維的變數必須都相同分佈 (identically distributed) 而且對原點對稱，否則旋轉後會改變分佈。那不妨假設一維的 PDF 是 <img src="https://latex.codecogs.com/png.latex?g(x)">，那旋轉不變性要求對於所有的 <img src="https://latex.codecogs.com/png.latex?n"> 維向量 <img src="https://latex.codecogs.com/png.latex?(x_1,%20x_2,%20%5Cldots,%20x_n)">，我們有： <img src="https://latex.codecogs.com/png.latex?%0Ag%5Cleft(%5Csqrt%7B%5Csum_%7Bi=1%7D%5En%20x_i%5E2%7D%20%5Cright)%20=%20%5Cprod_%7Bi=1%7D%5E%7Bn%7D%20g(x_i)%0A"> 令 <img src="https://latex.codecogs.com/png.latex?h(t)%20=%20%5Cln(g(%5Csqrt%7Bt%7D))">，我們有： <img src="https://latex.codecogs.com/png.latex?%0Ah%5Cleft(%5Csum_%7Bi=1%7D%5En%20x_i%5E2%5Cright)%20=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20h(x_i%5E2)%0A"> 這是柯西函數方程，因為 <img src="https://latex.codecogs.com/png.latex?h"> 是連續的，所以我們有 <img src="https://latex.codecogs.com/png.latex?h(t)%20=%20kt">，因此 <img src="https://latex.codecogs.com/png.latex?g(x)%20=%20e%5E%7Bkx%5E2%7D">。為了讓 <img src="https://latex.codecogs.com/png.latex?g(x)"> 成為一個合法的 PDF，我們需要 <img src="https://latex.codecogs.com/png.latex?k%3C0">，這正是常態分佈的形式！</p>
</section>
<section id="應用-樣本均值sample-mean-和-樣本變異數sample-variance-是獨立的" class="level3">
<h3 class="anchored" data-anchor-id="應用-樣本均值sample-mean-和-樣本變異數sample-variance-是獨立的">應用: 樣本均值(Sample Mean) 和 樣本變異數(Sample Variance) 是獨立的</h3>
<p>這算是一個神奇的應用場景吧! 假設有 <img src="https://latex.codecogs.com/png.latex?X_1,%20X_2,%20%5Cldots,%20X_n"> 是來自(一維)常態分佈 <img src="https://latex.codecogs.com/png.latex?%5Cmathcal%7BN%7D(%5Cmu,%20%5Csigma%5E2)"> 的獨立同分佈樣本 (i.i.d. samples)。我們定義樣本均值和樣本變異數如下： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbar%7BX%7D%20=%20%5Cfrac%7B1%7D%7Bn%7D%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20X_i,%20%5Cquad%20S%5E2%20=%20%5Cfrac%7B1%7D%7Bn-1%7D%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cbar%7BX%7D)%5E2%0A"> 那麼 <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BX%7D"> 和 <img src="https://latex.codecogs.com/png.latex?S%5E2"> 是獨立的隨機變數！</p>
<p>我們將 <img src="https://latex.codecogs.com/png.latex?n"> 個sample視為是 <img src="https://latex.codecogs.com/png.latex?n"> 維空間的隨機向量，<img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D%20=%20%5BX_1,%20X_2,%20%5Cldots,%20X_n%5D%5ET">。 因為i.i.d. 所以是multivariate normal，<img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D%20%5Csim%20%5Cmathcal%7BN%7D_n(%5Cmu%20%5Cmathbf%7B1%7D_n,%20%5Csigma%5E2%20I_n)">。</p>
<p>要減去常數向量 <img src="https://latex.codecogs.com/png.latex?%5Cmu%20%5Cmathbf%7B1%7D_n=%20%5B%5Cmu,%20%5Cmu,%20%5Cldots,%20%5Cmu%5D%5ET"> 後，<img src="https://latex.codecogs.com/png.latex?%5Cmathbf%7BX%7D%20-%20%5Cmu%20%5Cmathbf%7B1%7D_n"> 才有旋轉不變性 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:rotate_invar_shift%7D">。(隨然實驗學家不知道真的 <img src="https://latex.codecogs.com/png.latex?%5Cmu"> 是多少，但還是可以進行這樣的推導)。</p>
<p>令 <img src="https://latex.codecogs.com/png.latex?u_1%20=%20%5Cfrac%7B1%7D%7B%5Csqrt%7Bn%7D%7D%5B1,%201,%20%5Cldots,%201%5D%5ET">，這是一個單位向量 (unit vector)，代表均值的方向。然後選擇 <img src="https://latex.codecogs.com/png.latex?n-1"> 個正交於 <img src="https://latex.codecogs.com/png.latex?u_1"> 的單位向量 <img src="https://latex.codecogs.com/png.latex?u_2,%20u_3,%20%5Cldots,%20u_n">，所以 <img src="https://latex.codecogs.com/png.latex?%5Bu_1,%20u_2,%20%5Cldots,%20u_n%5D"> 形成一個正交矩陣 <img src="https://latex.codecogs.com/png.latex?Q">。令 <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathbf%7BY%7D%20%5Ccoloneqq%20Q%5ET%20(%5Cmathbf%7BX%7D%20-%20%5Cmu%20%5Cmathbf%7B1%7D_n)%0A"> ，其實也就是 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0AY_1%20&amp;%5Ccoloneqq%20u_1%5ET%20%5Ccdot%20(%5Cmathbf%7BX%7D%20-%20%5Cmu%20%5Cmathbf%7B1%7D_n),%20%5Cquad%20%5C%5C%0AY_i%20&amp;%5Ccoloneqq%20u_i%5ET%20%5Ccdot%20(%5Cmathbf%7BX%7D%20-%20%5Cmu%20%5Cmathbf%7B1%7D_n)%20%5Cquad%20%5Ctext%7B%20for%20%7D%20i=2,%203,%20%5Cldots,%20n%0A%5Cend%7Baligned%7D%0A"> 根據旋轉不變性 <img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:rotate_invar_shift%7D">，我們有 <img src="https://latex.codecogs.com/png.latex?Y_1,%20Y_2,%20%5Cldots,%20Y_n"> 是獨立的隨機變數，並且 <img src="https://latex.codecogs.com/png.latex?%0A%7C%7C%5Cmathbf%7BY%7D%7C%7C%5E2%20=%20%7C%7C%5Cmathbf%7BX%7D%20-%20%5Cmu%20%5Cmathbf%7B1%7D_n%7C%7C%5E2%20=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cmu)%5E2%0A"> 上面的等號就是個恆等式，僅代表作標轉換，並非取期望值什麼的。</p>
<p>這時看出來了嗎?</p>
<ul>
<li><img src="https://latex.codecogs.com/png.latex?%5Cbar%7BX%7D"> 是 <img src="https://latex.codecogs.com/png.latex?Y_1"> 的函數。因為 <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BX%7D%20=%20%5Cmu%20+%20%5Cfrac%7B1%7D%7B%5Csqrt%7Bn%7D%7D%20Y_1">。</li>
<li><img src="https://latex.codecogs.com/png.latex?S%5E2"> 是 <img src="https://latex.codecogs.com/png.latex?Y_2,%20Y_3,%20%5Cldots,%20Y_n"> 的函數。因為 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0A(n-1)S%5E2%0A&amp;=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cbar%7BX%7D)%5E2%20%20%20%5C%5C%0A&amp;=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cmu%20+%20%5Cmu%20-%20%5Cbar%7BX%7D)%5E2%20%20%20%5C%5C%0A&amp;=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cmu)%5E2%20+%202%5Csum_%7Bi=1%7D%5E%7Bn%7D(X_i%20-%20%5Cmu)(%5Cmu%20-%20%5Cbar%7BX%7D)%20+%20n(%5Cmu%20-%20%5Cbar%7BX%7D)%5E2%20%20%20%5C%5C%0A&amp;=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cmu)%5E2%20-%202n(%5Cmu%20-%20%5Cbar%7BX%7D)%5E2%20+%20n(%5Cmu%20-%20%5Cbar%7BX%7D)%5E2%20%20%20%5C%5C%0A&amp;=%20%5Csum_%7Bi=1%7D%5E%7Bn%7D%20(X_i%20-%20%5Cmu)%5E2%20-%20n(%5Cmu%20-%20%5Cbar%7BX%7D)%5E2%20%20%5C%5C%0A&amp;=%20%7C%7C%5Cmathbf%7BY%7D%7C%7C%5E2%20-%20Y_1%5E2%20=%20%5Csum_%7Bi=2%7D%5E%7Bn%7D%20Y_i%5E2%0A%5Cend%7Baligned%7D%0A"> 所以 <img src="https://latex.codecogs.com/png.latex?S%5E2%20=%20%5Cfrac%7B1%7D%7Bn-1%7D%20%5Csum_%7Bi=2%7D%5E%7Bn%7D%20Y_i%5E2">。</li>
</ul>
<blockquote class="blockquote">
<p>若隨機變數 <img src="https://latex.codecogs.com/png.latex?A,%20B"> 是獨立的，則對於任意(可測)函數 <img src="https://latex.codecogs.com/png.latex?f,%20g">。必定有 <img src="https://latex.codecogs.com/png.latex?f(A)"> 和 <img src="https://latex.codecogs.com/png.latex?g(B)"> 也是獨立的。</p>
</blockquote>
<p>如此一來就證明了 <img src="https://latex.codecogs.com/png.latex?%5Cbar%7BX%7D"> 和 <img src="https://latex.codecogs.com/png.latex?S%5E2"> 是獨立的隨機變數！ Q.E.D.</p>
<p>這裡也順便證明了一個經典結果：對於 <img src="https://latex.codecogs.com/png.latex?X_i%20%5Csim%20%5Cmathcal%7BN%7D(%5Cmu,%20%5Csigma%5E2)">，我們有 <img src="https://latex.codecogs.com/png.latex?%0A%5Cfrac%7B(n-1)S%5E2%7D%7B%5Csigma%5E2%7D%20%5Csim%20%5Cchi%5E2_%7Bn-1%7D%0A"> 這裡把高中時期統計學講的 「剩下<img src="https://latex.codecogs.com/png.latex?n-1">個自由度」給講得清清楚楚了。</p>


</section>

 ]]></description>
  <category>Normal Distribution</category>
  <guid>https://your-website-url.example.com/posts/normal-distribution/day_3.html</guid>
  <pubDate>Thu, 13 Nov 2025 16:00:00 GMT</pubDate>
</item>
<item>
  <title>一天證明一個 Normal Distribution 的性質 Day2：特徵函數(CF)與傅立葉變換</title>
  <dc:creator>Tai-Ning Liao</dc:creator>
  <link>https://your-website-url.example.com/posts/normal-distribution/day_2.html</link>
  <description><![CDATA[ 




<p>今天來講一下 moment generation function 跟 characteristic function。</p>
<p>對一個隨機變數 <img src="https://latex.codecogs.com/png.latex?X">，我們可以定義動差生成函數(Moment Generating Function, MGF): <img src="https://latex.codecogs.com/png.latex?%0AM_X(t)%20=%20E%5Be%5E%7BtX%7D%5D%0A"> 對於 <img src="https://latex.codecogs.com/png.latex?X%20%5Csim%20N(%5Cmu,%20%5Csigma%5E2)">，它的 MGF 為： <img src="https://latex.codecogs.com/png.latex?%0AM_X(t)%20=%20e%5E%7B%5Cmu%20t%20+%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D%0A"></p>
<p>讓我們假設隨機變數 <img src="https://latex.codecogs.com/png.latex?X"> 服從常態分佈，即 <img src="https://latex.codecogs.com/png.latex?X%20%5Csim%20N(%5Cmu,%20%5Csigma%5E2)">，其機率密度函數 (PDF) 為： <img src="https://latex.codecogs.com/png.latex?f(x;%20%5Cmu,%20%5Csigma%5E2)%20=%20%5Cfrac%7B1%7D%7B%5Csigma%5Csqrt%7B2%5Cpi%7D%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D%5Cleft(%5Cfrac%7Bx-%5Cmu%7D%7B%5Csigma%7D%5Cright)%5E2%7D,%20%5Cquad%20x%20%5Cin%20%5Cmathbb%7BR%7D%0A"></p>
<p>其中 <img src="https://latex.codecogs.com/png.latex?%5Cmu"> 是平均數（mean），<img src="https://latex.codecogs.com/png.latex?%5Csigma%5E2"> 是變異數（variance）。</p>
<p>帶入定義 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Baligned%7D%0AM_X(t)%0A&amp;=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Cfrac%7B1%7D%7B%5Csigma%5Csqrt%7B2%5Cpi%7D%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D%5Cleft(%5Cfrac%7Bx-%5Cmu%7D%7B%5Csigma%7D%5Cright)%5E2%7D%20e%5E%7Btx%7D%20%20dx%20%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7Du%5E2%20+%20t(%5Csigma%20u+%5Cmu)%20%7Ddx%0A%5Cqquad(%5Ctext%7Breplace:%7D%5Cquad%20x=%5Csigma%20u%20+%20%5Cmu)%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20e%5E%7B%5Cmu%20t%20+%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D(u%20-%20t%5Csigma%20)%5E2%7D%20du%20%5C%5C%0A&amp;=%20e%5E%7B%5Cmu%20t%20+%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D%20%5Cquad(%5Ctext%7B%E5%9B%A0%E7%82%BA%E9%AB%98%E6%96%AF%E7%A9%8D%E5%88%86%E7%9A%84%E7%B5%90%E6%9E%9C%E7%82%BA%20%7D%20%5Csqrt%7B2%5Cpi%7D)%20%5C%5C%0A%5Cend%7Baligned%7D%0A"></p>
<p>Characteristic function (CF) 定義為： <img src="https://latex.codecogs.com/png.latex?%20%20%0A%5Cphi_X(t)%20=%20E%5Be%5E%7BitX%7D%5D%0A"> 對於 <img src="https://latex.codecogs.com/png.latex?X%20%5Csim%20N(%5Cmu,%20%5Csigma%5E2)">，它的 CF 為： <img src="https://latex.codecogs.com/png.latex?%0A%5Cphi_X(t)%20=%20e%5E%7Bi%5Cmu%20t%20-%20%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20t%5E2%7D%20%5Ctag%7BGauss-CF%7D%5Clabel%7Beq:gauss%7D%0A"><br>
計算跟上面 MGF 類似，只是將 <img src="https://latex.codecogs.com/png.latex?t"> 換成 <img src="https://latex.codecogs.com/png.latex?it">。</p>
<section id="characteristic-的唯一性" class="level3">
<h3 class="anchored" data-anchor-id="characteristic-的唯一性">Characteristic 的唯一性</h3>
<p>CF 有一個重要的性質：它總是存在，因為 <img src="https://latex.codecogs.com/png.latex?%7Ce%5E%7BitX%7D%7C%20=%201">。 此外，CF 可以用來證明隨機變數的分佈唯一性：如果兩個隨機變數的 CF 相同，則它們的分佈也相同。這也將是我們今天的重點。讓我們來細細品味這個結果背後的意義與應用。</p>
<p>我們來看一個隨機變數 <img src="https://latex.codecogs.com/png.latex?X"> 的 CF： <img src="https://latex.codecogs.com/png.latex?%0A%5Cphi_X(t)%20=%20E%5Be%5E%7BitX%7D%5D%20=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7Bitx%7D%20f_X(x)%20dx%20%20%5Ctag%7B1%7D%5Clabel%7Beq:fourier%7D%0A"> 其中 <img src="https://latex.codecogs.com/png.latex?f_X(x)"> 是 <img src="https://latex.codecogs.com/png.latex?X"> 的機率密度函數 (PDF)。</p>
<p>我們來看看能不能從 CF 回推 PDF。我們可以把上式<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:fourier%7D">看成是一個傅立葉變換 (Fourier Transform)。 <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BF%7D%5Bf_X%5D(t)%20%5Ccoloneqq%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7Bitx%7D%20f_X(x)%20dx%20=%20%5Cphi_X(t)%0A"> 這邊的正負號和係數跟一般傅立葉變換的定義可能不太一樣，但本質上是一樣的。</p>
<p>我們想做個傅立葉「反」變換，大致上是：</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmathcal%7BF%7D%5E%7B-1%7D%5B%5Cphi_X%5D(x)%0A&amp;%5Ccoloneqq%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20%5Cphi_X(t)%20dt%20%20%20%5Ctag%7B2%7D%5Clabel%7Beq:fourier_inv%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20%5Cleft(%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7Bit%20y%7D%20f_X(y)%20dy%20%5Cright)%20dt%20%20%20%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%20%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20e%5E%7Bit%20y%7D%20f_X(y)%20dy%20dt%20%20%20%20%5C%5C%0A&amp;=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f_X(y)%20%5Cleft(%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7Bit(y%20-%20x)%7D%20dt%20%5Cright)%20dy%20%20%5Ctag%7B3%7D%5Clabel%7Beq:swap%7D%20%5C%5C%0A&amp;=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f_X(y)%20%5Cdelta(y%20-%20x)%20dy%20%5Cqquad%5Ctext%7B(Why?)%7D%20%5Ctag%7B4%7D%5Clabel%7Beq:delta%7D%20%20%5C%5C%0A&amp;=%20f_X(x)%20%20%5C%5C%0A%5Cend%7Balign%7D%0A"></p>
<p>大致上的感覺是這樣，但中間的步驟有些含糊，特別是涉及到狄拉克 delta 函數的部分。我們需要一些條件來保證這些積分的交換是合法的。確切來說<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:swap%7D"> 使用的積分順序的調換，是Fubini 定理的應用，而<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:delta%7D"> 則是利用了狄拉克 delta 函數的定義。</p>
<p>而Fubini定理要求的條件是被積分函數必須是絕對可積的 (absolutely integrable)，來檢查一下 <img src="https://latex.codecogs.com/png.latex?%7Ce%5E%7B-itx%7De%5E%7Bity%7D%7C%20=%201">，所以 <img src="https://latex.codecogs.com/png.latex?%0A%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%7Ce%5E%7B-itx%7D%20e%5E%7Bity%7D%20f_X(y)%7C%20dy%20dt%0A=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%7Cf_X(y)%7C%20dy%20dt%0A=%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20dt%20=%20%5Cinfty%0A"></p>
<p>Boom! 這個條件不成立。</p>
<p>但這不代表結論是錯的，只是這個證明是錯的!直接調換順序是行不通的。</p>
<p>我們來欣賞一下大數學家是怎麼解決這個問題的。如果在積分內有個函數 <img src="https://latex.codecogs.com/png.latex?g(t)">，使得 <img src="https://latex.codecogs.com/png.latex?g(t)"> 是絕對可積的 (absolutely integrable)，那麼我們就可以使用Fubini定理來調換積分順序。</p>
<p>讓我們退回到第一條式子，假設有某個 <img src="https://latex.codecogs.com/png.latex?g(t)%5Cin%20L%5E1">，也就是說 <img src="https://latex.codecogs.com/png.latex?%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%7Cg(t)%7C%20dt%20%3C%20%5Cinfty">，那麼我們有：</p>
<p><img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20%5Ctextcolor%7Bred%7D%7Bg(t)%7D%20%5Cmathcal%7BF%7D%5Bf_X%5D(t)%20dt%20%5Ctag%7B5%7D%5Clabel%7Beq:ee1%7D%20%20%5C%5C%0A=%20&amp;%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20%5Ctextcolor%7Bred%7D%7Bg(t)%7D%20%5Cleft(%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7Bit%20y%7D%20f_X(y)%20dy%20%5Cright)%20dt%20%20%20%5C%5C%0A=%20&amp;%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%20%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20e%5E%7Bit%20y%7D%20f_X(y)%20%5Ctextcolor%7Bred%7D%7Bg(t)%7D%20dy%20dt%20%20%5C%5C%0A=%20&amp;%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20%20%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20e%5E%7Bit%20y%7D%20f_X(y)%20%5Ctextcolor%7Bred%7D%7Bg(t)%7D%20dt%20dy%20%20%5Cqquad%5Ctext%7B(%E5%8F%AF%E4%BB%A5%E4%BA%A4%E6%8F%9B%E4%BA%86!)%7D%20%5C%5C%0A=%20&amp;%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f_X(y)%20%5Cleft(%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-it(x%20-%20y)%7D%20%5Ctextcolor%7Bred%7D%7Bg(t)%7D%20dt%20%5Cright)%20dy%20%20%5C%5C%0A=%20&amp;%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f_X(y)%20%5Ccdot%20%5Ctextcolor%7Bred%7D%7B%5Cmathcal%7BF%7D%5E%7B-1%7D%5Bg%5D%7D(x%20-%20y)%20dy%20%20%5Cqquad%5Ctext%7B(%E5%89%9B%E5%A5%BD%E6%98%AF%7Dg%5Ctext%7B%E7%9A%84%E5%82%85%E7%AB%8B%E8%91%89%E5%8F%8D%E8%BD%89%E6%8F%9B)%7D%20%5Ctag%7B6%7D%5Clabel%7Beq:ee2%7D%20%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 積分順序可以交換是因為 <img src="https://latex.codecogs.com/png.latex?g(t)%5Cin%20L%5E1">。這時候分析的大絕招來了，取極限!我們讓 <img src="https://latex.codecogs.com/png.latex?g(t)"> 慢慢逼近常數函數 <img src="https://latex.codecogs.com/png.latex?1">，然後看看右邊會變成什麼。</p>
<p>但我們要取個已知傅立葉反變換的 <img src="https://latex.codecogs.com/png.latex?g(t)">，例如我們剛剛算的高斯分布PDF: <img src="https://latex.codecogs.com/png.latex?g(t)%20=%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%20%5Csigma%5E2%7D%7De%5E%7B-t%5E2/2%5Csigma%5E2%7D">，其傅立葉反變換也是高斯函數： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A&amp;%5Cmathcal%7BF%7D%5E%7B-1%7D%5Bg%5D(x)%20%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cmathcal%7BF%7D%5Bg%5D(-x)%20%20%5Cqquad%5Ctext%7B(%E9%80%99%E6%98%AF%E6%A0%B9%E6%93%9A%E5%AE%9A%E7%BE%A9)%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20(-x)%5E2%7D%20%20%5Cqquad%5Ctext%7B(%E6%A0%B9%E6%93%9A%5Ceqref%7Beq:gauss%7D)%7D%20%5C%5C%0A&amp;=%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20x%5E2%7D%20%20%5Ctag%7B7%7D%5Clabel%7Beq:gauss_inv%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"><br>
但這個 <img src="https://latex.codecogs.com/png.latex?g"> 隨著 <img src="https://latex.codecogs.com/png.latex?%5Csigma%20%5Cto%20%5Cinfty">，會趨近於常數函數 <img src="https://latex.codecogs.com/png.latex?0">。我們要把常數乘回去(傅立葉變換是線性的)，所以我們其實是要定義 <img src="https://latex.codecogs.com/png.latex?%0Ag_%7B%5Csigma%7D(t)%20%5Ccoloneqq%20e%5E%7B-t%5E2/2%5Csigma%5E2%7D%0A"> 根據<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:gauss_inv%7D">，其傅立葉反變換為 <img src="https://latex.codecogs.com/png.latex?%0A%5Cmathcal%7BF%7D%5E%7B-1%7D%5Bg_%7B%5Csigma%7D%5D(x)%20=%20%5Cfrac%7B%5Csigma%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20x%5E2%7D%0A"> 我們代回<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:ee1%7D">和<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:ee2%7D">，得到 <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20%5Ctextcolor%7Bred%7D%7Bg_%7B%5Csigma%7D(t)%7D%20%5Cmathcal%7BF%7D%5Bf_X%5D(t)%20dt%0A=%20&amp;%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f_X(y)%20%5Ccdot%20%5Ctextcolor%7Bred%7D%7B%5Cmathcal%7BF%7D%5E%7B-1%7D%5Bg_%7B%5Csigma%7D%5D%7D(x%20-%20y)%20dy%20%20%5C%5C%0A=%20&amp;%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f_X(y)%20%5Ccdot%20%5Cfrac%7B%5Csigma%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20(x%20-%20y)%5E2%7D%20dy%20%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 我們 <img src="https://latex.codecogs.com/png.latex?%5Csigma"> 趨近於無窮大後等式就成立了，這需要兩個極限的等式： <img src="https://latex.codecogs.com/png.latex?%0A%5Cbegin%7Balign%7D%0A%5Cmathcal%7BF%7D%5E%7B-1%7D%5B%5Cmathcal%7BF%7D%5Bf_X%5D%5D(x)%0A&amp;=%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20%5Cmathcal%7BF%7D%5Bf_X%5D(t)%20dt%20%20%5Cqquad%5Ctext%7B(%E9%80%99%E6%98%AF%E7%94%A8%E5%82%85%E7%AB%8B%E8%91%89%E5%8F%8D%E8%AE%8A%E6%8F%9B%E7%9A%84%E5%AE%9A%E7%BE%A9)%7D%20%20%5C%5C%0A&amp;=%20%5Clim_%7B%5Csigma%20%5Cto%20%5Cinfty%7D%20%5Cfrac%7B1%7D%7B2%5Cpi%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20e%5E%7B-itx%7D%20g_%7B%5Csigma%7D(t)%20%5Cmathcal%7BF%7D%5Bf_X%5D(t)%20dt%20%20%5Ctag%7B8%7D%5Clabel%7Beq:lim1%7D%20%20%5C%5C%0A&amp;=%20%5Clim_%7B%5Csigma%20%5Cto%20%5Cinfty%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f_X(y)%20%5Ccdot%20%5Cfrac%7B%5Csigma%7D%7B%5Csqrt%7B2%5Cpi%7D%7D%20e%5E%7B-%5Cfrac%7B1%7D%7B2%7D%5Csigma%5E2%20(x%20-%20y)%5E2%7D%20dy%20%20=%20f_X(x)%20%20%5Cqquad%5Ctext%7B(%E6%A0%B9%E6%93%9A%E4%B8%8A%E9%9D%A2%E7%9A%84%E6%8E%A8%E5%B0%8E)%7D%20%5C%5C%0A&amp;=%20%5Clim_%7B%5Cepsilon%20%5Cto%200%5E%7B+%7D%7D%20%5Cint_%7B-%5Cinfty%7D%5E%7B%5Cinfty%7D%20f_X(y)%20%5Ccdot%20%5Cfrac%7B1%7D%7B%5Csqrt%7B2%5Cpi%20%5Cepsilon%5E2%7D%7D%20e%5E%7B-%5Cfrac%7B(x%20-%20y)%5E2%7D%7B2%5Cepsilon%5E2%7D%7D%20dy%20%20=%20f_X(x)%20%20%5Ctag%7B9%7D%5Clabel%7Beq:lim2%7D%20%5C%5C%0A%5Cend%7Balign%7D%0A"> 而<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:lim1%7D">是對的因為可以用 dominated convergence theorem。</p>
<p>而<img src="https://latex.codecogs.com/png.latex?%5Ceqref%7Beq:lim2%7D">仔細一看，他就是 <img src="https://latex.codecogs.com/png.latex?f_X"> 跟一個高斯核函數 (Gaussian Kernel) 的捲積 (convolution)。而這個高斯核函數的變異數趨近於 <img src="https://latex.codecogs.com/png.latex?0">。</p>
<p>這可以用非常基礎的古典論證，我就簡單寫寫: 我們將這個積分切分成兩個區間，一個是 <img src="https://latex.codecogs.com/png.latex?%7Cx%20-%20y%7C%20%3C%20%5Cdelta">，另一個是 <img src="https://latex.codecogs.com/png.latex?%7Cx%20-%20y%7C%20%5Cge%20%5Cdelta">。那個 <img src="https://latex.codecogs.com/png.latex?%7Cx%20-%20y%7C%20%3C%20%5Cdelta"> 的部分核函數總面積會趨近於1，而另一個部分因為核函數在 <img src="https://latex.codecogs.com/png.latex?%7Cx%20-%20y%7C%20%5Cge%20%5Cdelta"> 的地方會趨近於0，所以整個積分就會趨近於 <img src="https://latex.codecogs.com/png.latex?f_X(x)"> 在 <img src="https://latex.codecogs.com/png.latex?y=x"> 附近的平均值。若 <img src="https://latex.codecogs.com/png.latex?f_X"> 在 <img src="https://latex.codecogs.com/png.latex?x"> 點連續，那麼這個平均值就會趨近於 <img src="https://latex.codecogs.com/png.latex?f_X(x)">。若 <img src="https://latex.codecogs.com/png.latex?f_X"> 在 <img src="https://latex.codecogs.com/png.latex?x"> 點不連續，那麼這個極限會趨近於 <img src="https://latex.codecogs.com/png.latex?f_X"> 在 <img src="https://latex.codecogs.com/png.latex?x"> 點的連續化 (continuous version)。</p>
</section>
<section id="至於-levys-continuity-theorem" class="level3">
<h3 class="anchored" data-anchor-id="至於-levys-continuity-theorem">至於 Levy’s Continuity Theorem</h3>
<p>上面的證明解釋了一個分布的 characteristic function 唯一決定了該分布的概率密度函數 (PDF)，這是Levy’s Continuity Theorem 的一個重要部分。更完整的Levy’s Continuity Theorem 除了說明 CF 唯一決定分布外，還說明了如果一列隨機變數的 CF 收斂到某個函數，且該函數是某個分布的 CF，那麼這列隨機變數的分布也會收斂到該分布。</p>
<blockquote class="blockquote">
<p><strong>定理 1.1 (Lévy 連續性定理)</strong> 設 <img src="https://latex.codecogs.com/png.latex?%5Cmu,%20%5Cmu_n,%20n%20%5Cin%20%5Cmathbb%7BN%7D,"> 是定義在 <img src="https://latex.codecogs.com/png.latex?(%5Cmathbb%7BR%7D%5Ed,%20%5Cmathcal%7BB%7D(%5Cmathbb%7BR%7D%5Ed))"> 上的概率測度，其對應的特徵函數分別為 <img src="https://latex.codecogs.com/png.latex?%5Cchi"> 和 <img src="https://latex.codecogs.com/png.latex?%5Cchi_n,%20n%20%5Cin%20%5Cmathbb%7BN%7D">。則以下條件是等價的：</p>
<ol type="i">
<li>序列 <img src="https://latex.codecogs.com/png.latex?(%5Cmu_n)_%7Bn%20%5Cin%20%5Cmathbb%7BN%7D%7D"> 弱收斂於 <img src="https://latex.codecogs.com/png.latex?%5Cmu">。</li>
<li><img src="https://latex.codecogs.com/png.latex?%5Clim_%7Bn%20%5Cto%20%5Cinfty%7D%20%5Cchi_n(t)%20=%20%5Cchi(t)"> 對於所有 <img src="https://latex.codecogs.com/png.latex?t%20%5Cin%20%5Cmathbb%7BR%7D%5Ed"> 成立。</li>
</ol>
</blockquote>
<hr>
</section>
<section id="interactive-常態分佈與其傅立葉變換" class="level3">
<h3 class="anchored" data-anchor-id="interactive-常態分佈與其傅立葉變換">Interactive 常態分佈與其傅立葉變換</h3>
<p>這是一個互動式視覺化，展示 Normal Distribution <img src="https://latex.codecogs.com/png.latex?N(%5Cmu,%20%5Csigma%5E2)"> 及其 Fourier Transform。 特別注意 3D 圖中的<strong>螺旋結構</strong>：當 <img src="https://latex.codecogs.com/png.latex?%5Cmu%20%5Cneq%200"> 時，頻域會產生旋轉（Phase Shift）。</p>
<div id="cf-controls" style="margin-bottom:12px; display:flex; gap:12px; align-items:center;">
  <label>Mean (μ): <input id="mu" type="range" min="-3" max="3" step="0.1" value="0"></label>
  <span id="mu-val">0.0</span>
  <label>Variance (σ²): <input id="sigmaSq" type="range" min="0.1" max="10" step="0.1" value="1.0"></label>
  <span id="sigma-val">1.0</span>
</div>

<div id="pdf-plot" style="width:48%; display:inline-block; vertical-align:top;"></div>
<div id="ft-plot" style="width:50%; display:inline-block; vertical-align:top;"></div>

<script src="https://cdn.plot.ly/plotly-2.27.0.min.js"></script>
<script>
(() => {
  const n = 500;
  const xMin = -10, xMax = 10;
  const fMin = -3, fMax = 3;

  const xArr = Array.from({length:n}, (_,i) => xMin + (i/(n-1))*(xMax-xMin));
  const fArr = Array.from({length:n}, (_,i) => fMin + (i/(n-1))*(fMax-fMin));

  const muEl = document.getElementById('mu');
  const sigmaEl = document.getElementById('sigmaSq');
  const muVal = document.getElementById('mu-val');
  const sigmaVal = document.getElementById('sigma-val');

  function compute(mu, sigmaSq) {
    const sigma = Math.sqrt(sigmaSq);
    const pdf = xArr.map(x => (1/(sigma*Math.sqrt(2*Math.PI))) * Math.exp(-0.5*Math.pow((x-mu)/sigma,2)));
    const ft = fArr.map(xi => {
      const magnitude = Math.exp(-2*Math.pow(Math.PI,2)*sigmaSq*xi*xi);
      const phase = -2*Math.PI*mu*xi;
      return { xi, real: magnitude*Math.cos(phase), imag: magnitude*Math.sin(phase) };
    });
    return { pdf, ft };
  }

  let mu = parseFloat(muEl.value);
  let sigmaSq = parseFloat(sigmaEl.value);
  muVal.textContent = mu.toFixed(1);
  sigmaVal.textContent = sigmaSq.toFixed(1);

  const init = compute(mu, sigmaSq);

  const pdfTrace = { x: xArr, y: init.pdf, type: 'scatter', mode: 'lines', line: { color: 'steelblue' } };
  Plotly.newPlot('pdf-plot', [pdfTrace], { title: 'Probability Density', xaxis: {range:[xMin,xMax]}, yaxis:{range:[0,1.5]} }, {responsive:true});

  const ftTrace = { type:'scatter3d', mode:'lines', x: init.ft.map(d=>d.xi), y: init.ft.map(d=>d.real), z: init.ft.map(d=>d.imag), line:{width:4,color:init.ft.map(d=>d.xi),colorscale:'Viridis'} };
  const ftLayout = {
    margin:{l:0,r:0,b:0,t:30},
    scene:{
      aspectmode:'manual',
      aspectratio:{x:2,y:1,z:1},
      xaxis:{title:'Frequency (ξ)'},
      yaxis:{title:'Real'},
      zaxis:{title:'Imaginary'},
      // Camera: look roughly along the z-axis so the imaginary axis is perpendicular to the screen
      camera: {
        eye: { x: 0.0, y: 0.0, z: 2.5 },
        center: { x: 0.0, y: 0.0, z: 0.0 },
        up: { x: 0.0, y: 1.0, z: 0.0 }
      }
    }
  };
  Plotly.newPlot('ft-plot', [ftTrace], ftLayout, {responsive:true});

  let savedCamera = null;
  const ftDiv = document.getElementById('ft-plot');
  ftDiv.on('plotly_relayout', (d) => {
    if (d['scene.camera']) { savedCamera = d['scene.camera']; }
    else if (ftDiv._fullLayout && ftDiv._fullLayout.scene && ftDiv._fullLayout.scene.camera) {
      savedCamera = JSON.parse(JSON.stringify(ftDiv._fullLayout.scene.camera));
    }
  });

  let timer = null;
  function scheduleUpdate() {
    if (timer) clearTimeout(timer);
    timer = setTimeout(() => {
      const mu = parseFloat(muEl.value);
      const sigmaSq = parseFloat(sigmaEl.value);
      muVal.textContent = mu.toFixed(1);
      sigmaVal.textContent = sigmaSq.toFixed(1);
      const { pdf, ft } = compute(mu, sigmaSq);

      Plotly.restyle('pdf-plot', { y: [pdf] }, [0]);

      const fallback = (ftDiv._fullLayout && ftDiv._fullLayout.scene && ftDiv._fullLayout.scene.camera) ? JSON.parse(JSON.stringify(ftDiv._fullLayout.scene.camera)) : null;
      const keepCam = savedCamera || fallback;

      Plotly.restyle('ft-plot', { x: [ft.map(d=>d.xi)], y: [ft.map(d=>d.real)], z: [ft.map(d=>d.imag)], 'line.color': [ft.map(d=>d.xi)] }, [0]).then(() => {
        if (keepCam) setTimeout(() => Plotly.relayout('ft-plot', {'scene.camera': keepCam}).catch(()=>{}), 10);
      }).catch(() => {
        Plotly.react('ft-plot', [{ type:'scatter3d', mode:'lines', x: ft.map(d=>d.xi), y: ft.map(d=>d.real), z: ft.map(d=>d.imag), line:{width:4,color:ft.map(d=>d.xi),colorscale:'Viridis'} }], ftLayout).then(() => {
          if (keepCam) Plotly.relayout('ft-plot', {'scene.camera': keepCam}).catch(()=>{});
        });
      });

    }, 50);
  }

  muEl.addEventListener('input', scheduleUpdate);
  sigmaEl.addEventListener('input', scheduleUpdate);

})();
</script>


</section>

 ]]></description>
  <category>Normal Distribution</category>
  <guid>https://your-website-url.example.com/posts/normal-distribution/day_2.html</guid>
  <pubDate>Wed, 12 Nov 2025 16:00:00 GMT</pubDate>
</item>
</channel>
</rss>
