MCMCサンプリングって何をするもの
MCMC (マルコフ連鎖モンテカルロ法)サンプリングが結局何をしているかというと,
サンプリングという名の通り,未知の確率分布のサンプリングをしている.
例えば未知の確率分布を推定したいが,
解析的に解けないので数値的に解くことにする.
そういうとき,MCMCサンプリングによって,(十分大きな)標本列を生成することで,そののヒストグラムそのもの,あるいは平均・分散・中央値などから擬似的に確率分布を再現できる.
なぜMCMCがベイズ統計学とよく一緒に使われるのかというと,がある分布のパラメータだとみなせば,MCMCサンプリングによって得られた標本列で表現できる分布は,パラメータの確率分布だからである.
これがパラメータの確率分布であるということは,まさにベイズ統計でやろうとしていることそのもの.
MCMCとベイズ統計学はそれぞれ独自に発達してきた歴史を持つが,現在のところ非常に相性の良い組み合わせと言える.
IPython Notebookの自動カッコ補完を無効にする
http://stackoverflow.com/questions/22843891/turn-off-auto-closing-parentheses-in-ipython
IPython Notebookの自動カッコ補完を無効にするには、
~/.ipython/profile_default/static/custom/custom.js
に次を書き加えば良い:
if (IPython.CodeCell) {
IPython.CodeCell.options_default.cm_config.autoCloseBrackets = false;
}
matplotlibのArtistの階層構造
matplotlibのArtist(ユーザが意識して使っているクラス、FigureとかAxesとかAxisとか)は普通は階層構造を持つことになる。
例えば次のように図を作ると:
>>> fig = plt.figure() >>> ax1 = fig.add_subplot(211) >>> line = ax1.plot(np.sin(np.arange(0,10,0.1))) >>> ax2 = fig.add_subplot(212) >>> scat = ax2.scatter(*(np.random.rand(2,100))) >>> fig.show()
次のように階層構造があらわれる:
matplotlib.axes.Axesのhelper methodsで作られたArtistsがどのcontainerに格納されるか
参考:Artist tutorial — Matplotlib 1.4.2 documentation
matplotlib.axes.Axes(一番良く使うArtists:subplotとか)のhelper methods(bar, plot, scatterなど)で作られたArtistsがどのcontainerに格納されるか:
Helper method | Artist | Container |
---|---|---|
Axes.annotate - text annotations | Annotate | Axes.texts |
Axes.bar - bar charts | Rectangle | Axes.patches |
Axes.errorbar - error bar plots | Line2D and Rectangle | Axes.lines and Axes.patches |
Axes.fill - shared area | Polygon | Axes.patches |
Axes.hist - histograms | Rectangle | Axes.patches |
Axes.imshow - image data | AxesImage | Axes.images |
Axes.legend - axes legends | Legend | Axes.legends |
Axes.plot - xy plots | Line2D | Axes.lines |
Axes.scatter - scatter charts | PolygonCollection | Axes.collections |
Axes.text - text | Text | Axes.texts |
`patches`だけちょっとわかりにくいが、長方形全般を格納するcontainer。
そもそもAxesがどういったcontainer(と属性)を持っているか、代表的なものを挙げると:
Axes attribute | Description |
---|---|
Axes.artists | A list of Artist instances |
Axes.patch | Rectangle instance for Axes background |
Axes.collections | A list of Collection instances |
Axes.images | A list of AxesImage |
Axes.legends | A list of Legend instances |
Axes.lines | A list of Line2D instances |
Axes.patches | A list of Patch instances |
Axes.texts | A list of Text instances |
Axes.xaxis | matplotlib.axis.XAxis instance |
Axes.yaxis | matplotlib.axis.YAxis instance |
特に、`patch`と`patches`が紛らわしいので注意。
`patch`がAxesの背景の長方形(つまりひとつ)、`patches`がAxesが持ってる長方形のcontainer(つまりhist()とかで生成される長方形のリスト)。
matplotlibで背景の色や透明度を設定する - How to set the background color and transparency in matplotlib
参考:matplotlib公式のArtist tutorial
JP
matplotlibでプロットの背景の色や透明度の設定方法:
>>> import matplotlib.pyplot as plt >>> fig = plt.figure() # Figure >>> ax = fig.add_subplot(211) # Axes >>> fig.patch.set_facecolor('blue') # 図全体の背景色 >>> fig.patch.set_alpha(0.5) # 図全体の背景透明度 >>> ax.patch.set_facecolor('green') # subplotの背景色 >>> ax.patch.set_alpha(0.3) # subplotの背景透明度
subplotの緑色の透明度が0.3と低いので図全体の背景色の青に負けていますね
EN
How to set the plot's background color or transparency in matplotlib:
>>> import matplotlib.pyplot as plt >>> fig = plt.figure() # Figure >>> ax = fig.add_subplot(211) # Axes >>> fig.patch.set_facecolor('blue') # change the background color of the figure >>> fig.patch.set_alpha(0.5) # change the background transparency of the figure >>> ax.patch.set_facecolor('green') # change the background color of the subplot >>> ax.patch.set_alpha(0.3) # change the background transparency of the subplot
Because the transparency of subplot's background green is 0.3, it seems like blue which is the Figure's background color.
「情報系」と「電気系」は同じ学部?
歴史的な事情もあって,「情報系」と「電気系」は同じカテゴリにされることが多いけど,情報系と電気系とは本質的に関係はないと思う.
これまでの科学で計算機を構築するためには電気回路が都合が良かっただけで,もしもメカニカルな機構のほうが効率が良かったら機械系と情報系が同じカテゴリにされていただろうし,粘菌コンピュータのほうが効率がよかったら生物系と情報系が同じカテゴリにされていただろう.
情報系は電気回路を手段として使っているだけであって,本質的に学問したいのは仮想的な計算機なことが多い(チューリングマシン,オートマトン,コンパイラ等).
電気系と情報系を同じカテゴリにするのは,「数学はギリシア文字をたくさん使うからギリシア文学と同じカテゴリ」って言ってるのと近いものを感じる.