Skip to content

Instantly share code, notes, and snippets.

@tanutarou
tanutarou / pennygame.py
Created December 25, 2015 05:00
Penney's game simulation
import numpy as np
N = 10000
winfreq = np.array([0, 0])
playerA = "111"
playerB = "011"
for i in xrange(N):
res = [2, 2, 2]
while True:
@tanutarou
tanutarou / narcissistic.py
Created May 25, 2017 11:27
Narcissistic Number Generator
import numpy as np
import operator
def rec(idx, nums, digit):
if idx == 9:
if sum(nums) == digit:
cand = reduce(operator.add, [cnt * (power[9-i][digit]) for i, cnt in enumerate(nums)])
bin_cand = [0 for i in xrange(10)]
for i in str(cand):
bin_cand[9-int(i)] += 1
@tanutarou
tanutarou / monte_carlo_pi.ipynb
Created September 3, 2017 06:32
Calculation of Pi Using the Monte Carlo Method
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tanutarou
tanutarou / mcmc.ipynb
Last active September 5, 2017 12:22
『計算統計Ⅱ マルコフ連鎖モンテカルロ法とその周辺』 第1部2章の再現コード (p.8~28)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tanutarou
tanutarou / file0.txt
Created September 23, 2017 11:09
EMアルゴリズムのメモ 「ベイズ推定とグラフィカルモデル:コンピュータビジョン基礎1 セクション7」 ref: http://qiita.com/tanutarou/items/de149f39a52a4c207e3f
\begin{eqnarray}
\sum_i \sum_{k=1}^K q_i(z_k)\ln \left[\frac{p(x_i, z_k|\theta)}{q_i(z_k)} \right] &=& \sum_i \sum_{k=1}^K q_i(z_k)\ln \left[ \frac{p(z_k|x_i,\theta)p(x_i|\theta)}{q_i(z_k)} \right] \\
&=&\sum_i \sum_{k=1}^K q_i(z_k)\ln \left[ p(x_i|\theta) \right] + \sum_i \sum_{k=1}^K q_i(z_k) \ln\left[ \frac{p(z_k|x_i, \theta)}{q_i(z_k)} \right] \\
&=& \sum_i \ln \left[ p(x_i|\theta) \right] +\sum_i \sum_{k=1}^K q_i(z_k) \ln \left[ \frac{p(z_k|x_i, \theta)}{q_i(z_k)} \right]
\end{eqnarray}
@tanutarou
tanutarou / bayesian_polyfit.ipynb
Created October 15, 2017 11:50
最小二乗法、ガウスノイズモデル、ベイズ線形回帰モデルによる多項式あてはめ
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tanutarou
tanutarou / bernoulli.ipynb
Last active November 25, 2017 06:49
ベルヌーイ試行のMAP推定、ベイズ推定の例:きのこ傘投げ問題
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tanutarou
tanutarou / categorical.ipynb
Last active December 8, 2017 22:31
カテゴリカル分布に対するベイズ推定(サイコロの出る目の確率推定)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tanutarou
tanutarou / poisson.ipynb
Last active August 31, 2022 21:03
ポアソン分布に対するベイズ推論(メール受信数を例に実験)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.