メタ構文変数,意味のない言葉のリスト
参考:http://dev.classmethod.jp/etc/metasyntactic-variables/
「メタ構文変数」とは,fooやbar,日本ではhogeやfugaなど,「意味のない」ことを意味する言葉たちです.一時的に何かをしたいときや,読者に対して「意味がない言葉である」ことを示すためにあえて使われたりします.
上記の記事でいろいろな例が挙げられており,また,メタ構文変数に備わっているべき性質も議論されています.それは「順番がわかるべき」「覚えやすく,判別しやすい」「ある程度の量が用意されている」などです.「順番がわかるべき」というのは,fooのあとはbarを使う,のようにメタ構文変数に順位があることです.これがあることで何番目の変数なのか,前にいくつ意味のない変数があるのかの把握が容易になります.また,「覚えやすく,判別しやすい」というのはそのままの意味です.もしもメタ構文変数としてhoge, honge, holge, horge, hodgeを使ったら,自分でもどれがどれかわからなくなる上に,口頭で人に伝えづらくなります.「ある程度の量が用意されている」というのは,意味のないシリーズの単語が3つで終わり,ではなくちゃんと9個10個ありますか?ということです.3個程度では足りなくなることがあります.
以上を踏まえて,次のようなメタ構文変数が上記の記事で挙げられています:
- foo, bar, baz, qux, quux, corge, grault, garply, waldo, fred, plugh, xyzzy, thud
- 順番はfoo,bar,bazあたりまでわかる.しかし,baz以降を覚えている人はあまりいないのでは・・・判別性も微妙.
- hoge, fuga, piyo, (hogehoge, mogera)...
- 順番はほぼ無い.私が日本人なので,覚えやすさはある.判別性もそこそこ.しかし,日本でしか通じない.
- spam, ham, eggs, ...
- 朝食シリーズ.順番は一応ある.Pythonでよく使われるらしい.種類が少なすぎる?
- Alice, Bob, Eve, ...
- 人名シリーズ.暗号界隈で使われる.人物AがAlice,人物BがBob,盗聴者(Eavesdropper)がEveなので順番があるし覚えやすい.判別性もよい.ただし,意味がない文字になっているかと言われると微妙.AliceさんもBobさんも存在するし・・・
他にもいろいろ考えてみました.日本でしか通用しそうにないものも混じっていますが・・・(もし他にあったらぜひ教えてください!):
- 甲・乙・丙・丁・戊・己・庚・辛・壬・癸
- 十干シリーズ.順番完璧.種類も10個と多い.しかし,おそらく日本(と中国?)でしか通じない.あと,判別性も微妙.庚と癸に至っては,どちらも「き」である.
- いろはにほへと...
- いろはシリーズ.順番完璧.種類も多い.日本でしか通じない.あと,あまりにも単語ひとつが短すぎるので微妙.
- 子丑寅卯辰巳午未申酉戌亥
- 十二支シリーズ.十干シリーズと同じメリットデメリットを抱える.
- ドレミファソラシ (Do Re Mi Fa Sol La Si)
- 音階シリーズ.日本以外でも通じそう(ドレミ,じゃなくてCDE,なことも多いけど).ただし,「ソ」だけ3文字で気に食わないのと,「Do」がやばすぎる*1ので非推奨っぽい.
- 月火水木金土日 (Mon, Tue, Wed, ...)
- 曜日シリーズ.世界どこでも通じそう.ただ,意味のない言葉かと言われると微妙.
- H, He, Li, Be,...
- 元素周期表シリーズ.同上.
- 水金地火木土天海 (Mercury, Venus, Earth)
- 太陽系シリーズ.順番良し.判別性よし.ただ,ちょっと単語ひとつが長いかも.ただし,オシャレである.
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.