Submit Search
Upload
Rで麻雀
•
Download as PPTX, PDF
•
1 like
•
2,612 views
M
mangantempy
Follow
第7回 R勉強会@東京 @mangantempyによるLT資料。
Read less
Read more
Report
Share
Report
Share
1 of 45
Download now
Recommended
アダルトデータマイニングの勧め
アダルトデータマイニングの勧め
Kensuke Mitsuzawa
麻雀牌譜解析のすすめ byほしきゅー
麻雀牌譜解析のすすめ byほしきゅー
Restar9
麻雀心理学のための統計学序説① 標準偏差
麻雀心理学のための統計学序説① 標準偏差
matanoseiko
サーバ異常検知入門
サーバ異常検知入門
mangantempy
Rのコードをキレイに見せたい
Rのコードをキレイに見せたい
mangantempy
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
Recommended
アダルトデータマイニングの勧め
アダルトデータマイニングの勧め
Kensuke Mitsuzawa
麻雀牌譜解析のすすめ byほしきゅー
麻雀牌譜解析のすすめ byほしきゅー
Restar9
麻雀心理学のための統計学序説① 標準偏差
麻雀心理学のための統計学序説① 標準偏差
matanoseiko
サーバ異常検知入門
サーバ異常検知入門
mangantempy
Rのコードをキレイに見せたい
Rのコードをキレイに見せたい
mangantempy
2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
Marius Sescu
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
Expeed Software
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
Pixeldarts
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
More Related Content
Featured
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
marketingartwork
Skeleton Culture Code
Skeleton Culture Code
Skeleton Technologies
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Neil Kimberley
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
contently
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Albert Qian
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
Search Engine Journal
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
SpeakerHub
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Tessa Mero
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Lily Ray
How to have difficult conversations
How to have difficult conversations
Rajiv Jayarajah, MAppComm, ACC
Introduction to Data Science
Introduction to Data Science
Christy Abraham Joy
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
Vit Horky
The six step guide to practical project management
The six step guide to practical project management
MindGenius
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson36
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter
ChatGPT webinar slides
ChatGPT webinar slides
Alireza Esmikhani
Featured
(20)
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
Skeleton Culture Code
Skeleton Culture Code
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
Getting into the tech field. what next
Getting into the tech field. what next
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
How to have difficult conversations
How to have difficult conversations
Introduction to Data Science
Introduction to Data Science
Time Management & Productivity - Best Practices
Time Management & Productivity - Best Practices
The six step guide to practical project management
The six step guide to practical project management
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
ChatGPT webinar slides
ChatGPT webinar slides
Rで麻雀
1.
Rで麻雀 2010.07.24 @mangantempy
2.
アジェンダ 自己紹介 このLTのねらい
麻雀のルール 下準備 面子の作りやすさ あがれる確率
3.
自己紹介 ID : @mangantempy 職業: Webエンジニア
学生時代: 数理情報科学授業についていけず数学嫌いに。 好きな物: 一風堂、マンガ、麻雀
4.
このLTのねらい Rを使ってみる 麻雀の研究
麻雀の布教
5.
麻雀のルール 互いに持ち点を奪い合うゲーム 25,000
0 Aさん Bさん Cさん Dさん
6.
麻雀のルール 互いに持ち点を奪い合うゲーム 25,000
0 Aさん Bさん Cさん Dさん
7.
麻雀のルール 互いに持ち点を奪い合うゲーム 25,000
0 Aさん Bさん Cさん Dさん
8.
麻雀のルール 互いに持ち点を奪い合うゲーム 25,000
0 Aさん Bさん Cさん Dさん
9.
麻雀のルール 136枚の「雀牌」を使う 萬子(マンズ)
筒子(ピンズ) 索子(ソウズ) 字牌(ジハイ) 34種類 * 各4枚 = 計136枚
10.
34種類 * 各4枚 = 計136枚
11.
Rでやると・・・ > (
9 + 9 + 9 + 7 ) * 4 [1] 136 >
12.
13.
麻雀のルール 和了(あがり)の形 14枚
3枚 3枚 3枚 3枚 2枚 順子(シュンツ) 刻子(コウツ) 雀頭(アタマ) 種類が同じで、 数字が3つ連続するような 3枚の牌の組み合わせ 同じ牌を3枚 同じ牌を2枚
14.
Rでやると・・・ > (
3 * 4 ) + 2 [1] 14 >
15.
16.
麻雀のルール 一翻役 平和
断ヤオ九 一盃口 立直 門前清自摸 翻牌 海底摸月 河底撈魚 嶺上開花 搶槓 一発 ドラ 二翻役 三色同順 一気通貫 対々和 七対子 全帯ヤオ 混老頭 三暗刻 三色同刻 三槓子 小三元 ダブルリーチ 三翻役 純全帯ヤオ 混一色 二盃口 役満 九連宝燈 緑一色 四暗刻 四槓子 清老頭 国士無双 大三元 小四喜 大四喜 字一色 天和 地和 人和 キレイな手ほど 点数が高い。 六翻役 清一色
17.
下準備 ここで一度麻雀からはなれて、 確率とRの一般的な話を。
18.
「階乗」をRでやると・・・ 𝑛!
> n <- 5 > prod(1:n)# 0! = 1 にならない [1] 120 > gamma(n+1) [1] 120 > factorial(1:5) # R 1.9 より登場 [1] 120
19.
「組み合わせ」をRでやると・・・ 𝑛𝐶𝑟=𝑛!𝑟!𝑛−𝑟!
> factorial(n) / (factorial(r) * factorial(n-r)) [1] 10 > choose(n, r) [1] 10
20.
「順列」をRでやると・・・ 𝑛𝑃𝑟=𝑛!𝑛−𝑟!
> r <- 2 > factorial(n) / factorial(n-r) [1] 20 > perm <- function(n, r) + factorial(n) / factorial(n-r) > perm(n, r) [1] 20
21.
「総和」をRでやると・・・ 𝑥=1𝑛𝑓𝑥=𝑓(1)+𝑓(2)+…+𝑓(𝑛)
> myfunc <- function(x) (x+1)^2 > sapply(1:5, myfunc) [1] 4 9 16 25 36 > sum(sapply(1:5, myfunc)) [1] 90
22.
【問題】 袋の中に全部で m
個のボールが入っており、 そのうち、アタリが t 個、ハズレが m-t 個とする。 この中から無作為に 1 個のボールを取り出し、 袋には戻さないという操作を k 回行う時、 k 回目で初めて当たりを引く確率は?
23.
【答え】 k-1 回連続でハズレを引く確率は、
k 回目でアタリを引く確率は、 求める確率は、 𝑃1=(𝑚−𝑡)𝑃(𝑘−1) 𝑚𝑃(𝑘−1) 𝑃2=𝑡 (𝑚−(𝑘−1)) 𝑃𝑎𝑡𝑎𝑟𝑖(𝑚,𝑡,𝑘)=𝑃1∗𝑃2=𝑚−𝑡𝑃𝑘−1∗𝑡 𝑚𝑃𝑘
24.
Rでやると・・・ 𝑃𝑎𝑡𝑎𝑟𝑖(𝑚,𝑡,𝑘)=𝑚−𝑡𝑃𝑘−1∗𝑡 𝑚𝑃𝑘
> Patari <- function(m, t, k) { + if ((m-t) < (k-1) || m < k) 0 # エラー処理 + else perm(m-t, k-1) * t / perm(m, k) # main + } 5個(アタリは 2 個)から、3 回目ではじめてアタリを引く確率 > Patari(5, 2, 3) [1] 0.2
25.
これで 道具は揃った。 話を麻雀に戻します。
26.
面子の作りやすさ 刻子が4つある場合… ⇒役は「四暗刻」。 32,000点~
順子が4つある場合… ⇒役は「平和」。 1,000点~ なんでそんなに違うの!?
27.
刻子と順子 を使った面子は・・・ 順子(シュンツ)
刻子(コウツ)
28.
29.
刻子と順子 を使った面子を作る。有効牌は? 順子(シュンツ)
刻子(コウツ) 有効牌:1種3枚
30.
31.
刻子と順子 を使った面子を作る。有効牌は? 順子(シュンツ)
刻子(コウツ) 有効牌:1種3枚 有効牌:4種8枚
32.
こんなシチュエーションを想定 今 を1枚と、無関係な牌2枚を持っていると仮定して、
(1) 残りの牌の中からランダムな牌を1枚引き、 (2) 不要な牌を1枚捨てる という操作を10回行うとき、 を含む刻子or順子が完成する確率は?
33.
34.
35.
刻子を作るには
36.
順子を作るには
37.
こんなシチュエーションを想定 今 を1枚と、無関係な牌2枚を持っていると仮定して、
(1) 残りの牌の中からランダムな牌を1枚引き、 (2) 不要な牌を1枚捨てる という操作を10回行うとき、 を含む刻子or順子が完成する確率は?
38.
つまり・・・ 全部で牌は136枚。 自分が最初に3枚持っているので、
残りは 136-3=133枚。 有効牌は、1種のみで残り3枚。 10回以内に、 3枚の有効牌のうち少なくとも2枚を引く。
39.
こう考える。 3枚の有効牌を含む133枚の牌の中から
i 回目ではじめて有効牌を引き、かつ 2枚の有効牌を含む133-i 枚の牌の中から j 回目ではじめて有効牌を引く。 求める確率は、1≦i<10, 1≦j≦10-iとなる すべての i, j についての確率の総和なので、 𝑃=𝑖=19𝑗=110−𝑖𝑃𝑎𝑡𝑎𝑟𝑖(133,3,𝑖)𝑃𝑎𝑡𝑎𝑟𝑖(133−𝑖,2,𝑗)
40.
Rでやると・・・ 𝑃=𝑖=19𝑃𝑎𝑡𝑎𝑟𝑖(133,3,𝑖)𝑗=110−𝑖𝑃𝑎𝑡𝑎𝑟𝑖(133−𝑖,2,𝑗)
> Pkotu <- function(zen, yuko, kaisu) { + sum(sapply(1:(kaisu-1), function(i) { + sum(sapply(1:(kaisu-i), function(j) { + Patari(zen, yuko, i) * Patari(zen-i, yuko-1, j) + })) + })) + } > Pkotu(133,3,10) [1] 0.01475323
41.
試行回数別に確率を見てみる > (
result <- sapply(2:133, + function(x) Pkotu(133,3,x)) ) [1] 0.0003417635 0.0010200727 0.0020297099 0.0033654574 0.0050220972 [6] 0.0069944118 0.0092771832 0.0118651939 0.0147532259 0.0179360615 [11] 0.0214084830 0.0251652727 0.0292012126 0.0335110851 0.0380896725 : [121] 0.9820639385 0.9852467741 0.9881348061 0.9907228168 0.9930055882 [126] 0.9949779028 0.9966345426 0.9979702901 0.9989799273 0.9996582365 [131] 1.0000000000 1.0000000000
42.
試行回数別に確率を見てみる > barplot(x,
names=2:133) #棒グラフ
43.
順子を作るには
44.
以下、同様に。 刻子の時と同様に確率を求める。 パターンが多いから、場合分けが必要
⇒ ⇒ ⇒ ⇒ ⇒ ⇒ グラフ化して、刻子のグラフと見比べる。 順子の方が断然作りやすい事が分かる!
45.
おしまい ありがとうございました。 @mangantempy
Download now