物理の駅 Physics station by 現役研究者

テクノロジーは共有されてこそ栄える

Python: 非対称な誤差の計算をモンテカルロシミュレーション法で計算する

Asymmetric uncertainties in measurements: SOAD a Python package based on Monte Carlo Simulations

https://aip.scitation.org/doi/abs/10.1063/1.5135421

という論文があったので使ってみた。数学的に正しいかどうかは確認していない

Githubソースコードは公開されている

github.com

Gitでcloneする

git clone https://github.com/kiyami/soad.git
cd soad

python setup.py install でインストールだが、README.mdがUTF-8で記述されてるのにエンコーディングが設定されていないので、setup.pyの5行目を以下のように変更する

#with open("README.md", "r") as fh:
with open("README.md", "r", encoding="utf-8") as fh:

インストール

python setup.py install

サンプルコードを実行してみる

from soad import AsymmetricData as asyd
a = asyd(10.0, 1.0, 1.2, N=10000, confidence=1.0)
b = asyd(15.0, 2.4, 2.1, N=10000, confidence=1.0)
c = a * b
print(c)
c.plot_data_and_pdf(show=True, save=False)
c.plot_log_likelihood(show=True, save=False)

出てくる絵は次の通り

f:id:onsanai:20210922110909p:plain

f:id:onsanai:20210922110928p:plain