(細かい修正なのであまり重要ではない) [c27e97f, a8e3dae, 4f5382f, e06d946, ca9f334] - pymc4のソースコード読んでみた
TL;DR
- 細かい修正が多いのであまり重要ではないです.
コミット
2018/06/26から2018/06/30の間のコミットです.
- minor fixes · pymc-devs/pymc4@c27e97f · GitHub
- add some tests · pymc-devs/pymc4@a8e3dae · GitHub
- add tests and fix model.configure() · pymc-devs/pymc4@4f5382f · GitHub
- fix lint errors · pymc-devs/pymc4@e06d946 · GitHub
- add tests · pymc-devs/pymc4@ca9f334 · GitHub
minor fixes - c27e97f
- pymc4/inference_sampling_sample.py
- dictのfor文の処理で不要な変数を減らしているだけです.
- pymc4/model/base.py
- target_log_prob_fnメソッド: この辺りは変更は多いがやっていることは変わらないため省略
- unobservedプロパティ: 順序付きdictの初期化の処理を修正
unobserved = {}
とdictを初期化するとpython3.5以下では順序無しのdictになる点を修正- see: Get mcmc sampling to work by sharanry · Pull Request #9 · pymc-devs/pymc4 · GitHub
add some tests - a8e3dae
- 実際にはテストの追加ではなくリファクタリングをしているだけなので省略
add tests and fix model.configure() - 4f5382f
次のようなテストが複数追加されている.
- Modelクラスのインスタンス化
@model.define
でed.Normal(0., 1., name='normal')
を生成したModelインスタンスにセット- assertでModelインスタンスのプロパティをチェック
model = pm.Model() @model.define def simple(cfg): ed.Normal(0., 1., name='normal') assert len(model.variables) == 1 assert len(model.unobserved) == 1 assert "normal" in model.variables
fix lint errors - e06d946
lint対応なので省略: #pylint: disable=unused-argument
でlintをdisableしている箇所もある.
add tests - ca9f334
テストが複数追加されている.
例えば, 次のテストは(対数)確率関数の値を近似的(approx)にチェックしている.
def test_model_log_prob_fn(): model = pm.Model() @model.define def simple(cfg): mu = ed.Normal(0., 1., name="mu") log_prob_fn = model.target_log_prob_fn() with tf.Session(): assert -0.91893853 == pytest.approx(log_prob_fn(0).eval(), 0.00001)
念のためにscipy.statsのdistributionモジュールで値をチェックしたみた.
from scipy.stats import norm print(norm(0, 1).logpdf(0)) # => -0.9189385332046727