Tigramite スライド ベイズ・確率プログラミング

Tigramite - 時系列データセットの因果推論

 Tigramiteは Jakob Runge氏らによる時系列データの因果推論を実行するベイジアンネットワークを含むPythonのツールです。GNU General Public License v3.0 で提供されています。

 Pearlの因果推論の理論を基礎にした確率的グラフィカルモデルを高品質な図で出力します。

 以下の印象深い図を参照してください。これは”Detecting and quantifying causal associations in large nonlinear time series datasets(参考文献)”からの引用です。

概要

 Tigramiteは時系列のための因果推論のPythonパッケージです。効果的に因果グラフを高次の時系列データセットから推定し、ロバスト予想、推定、有向、総合、予測、影響に効果のためにグラフを使います。因果の発見は、線形と同様に 離散、連続時系列の値に適用できるノンパラメトリック条件付き独立テストを基礎にしています。また、結果を高品質に図示する関数を含みます。以下の、あなたが使うメソッドに依存する論文を参照してください。

  • PCMCI: J. Runge, P. Nowack, M. Kretschmer, S. Flaxman, D. Sejdinovic, Detecting and quantifying causal associations in large nonlinear time series datasets. Sci. Adv. 5, eaau4996 (2019). https://advances.sciencemag.org/content/5/11/eaau4996
  • PCMCI+: J. Runge (2020): Discovering contemporaneous and lagged causal relations in autocorrelated nonlinear time series datasets. Proceedings of the 36th Conference on Uncertainty in Artificial Intelligence, UAI 2020,Toronto, Canada, 2019, AUAI Press, 2020. http://auai.org/uai2020/proceedings/579_main_paper.pdf
  • LPCMCI: Gerhardus, A. & Runge, J. High-recall causal discovery for autocorrelated time series with latent confounders Advances in Neural Information Processing Systems, 2020, 33.
  • RPCMCI: Elena Saggioro, Jana de Wiljes, Marlene Kretschmer, Jakob Runge; Reconstructing regime-dependent causal relationships from observational time series. Chaos 1 November 2020; 30 (11): 113115. https://doi.org/10.1063/5.0020538
  • Generally: J. Runge (2018): Causal Network Reconstruction from Time Series: From Theoretical Assumptions to Practical Estimation. Chaos: An Interdisciplinary Journal of Nonlinear Science 28 (7): 075310. https://aip.scitation.org/doi/10.1063/1.5025050
  • Nature Communications Perspective paper: https://www.nature.com/articles/s41467-019-10105-3
  • Mediation class: J. Runge et al. (2015): Identifying causal gateways and mediators in complex spatio-temporal systems. Nature Communications, 6, 8502. http://doi.org/10.1038/ncomms9502
  • Mediation class: J. Runge (2015): Quantifying information transfer and mediation along causal pathways in complex systems. Phys. Rev. E, 92(6), 62829. http://doi.org/10.1103/PhysRevE.92.062829
  • CMIknn: J. Runge (2018): Conditional Independence Testing Based on a Nearest-Neighbor Estimator of Conditional Mutual Information. In Proceedings of the 21st International Conference on Artificial Intelligence and Statistics. http://proceedings.mlr.press/v84/runge18a.html
  • CausalEffects: J. Runge, Necessary and sufficient graphical conditions for optimal adjustment sets in causal graphical models with hidden variables, Advances in Neural Information Processing Systems, 2021, 34.

特徴

  • 柔軟な条件独立テスト連続する値、離散、混合データに適合した統計、そして線形、非線形に関する異なる仮定。
  • 欠測データとマスクのハンドリング
  • P-valueの訂正と信頼度の推定
  • ノンパラメトリックに推定する因果の効果と線形に影響する因果のための因果クラス
  • 因果の特徴選択を含むskleanモデルを基礎にした予測クラス

インストール

 Tigmaiteをインストールするには、以下のURLのgithubのサイトに移動し、Pythonのアーカイブでzipファイルをダウンロードしてください。現在のバージョンは5.2です。

https://github.com/jakobrunge/tigramite

 このサイトの上部に緑色のコードボタンがあります。このボタンをクリックすると、プルダウンメニューが開きます。

 ここでDownload ZIPメニューをクリックするとダウンロードを開始します。

 ダウンロードしたzipファイルを解凍すると、ダウンロードしたディレクトリにtigamite-masterというディレクトリが作られます。これをローカルの適当なパスに移して使ってください。

 インストールするには、ローカルのこのディレクトリに移動し、以下のコマンドを実行します。

$ cd tigramite-master/
$ python setup.py install

 以下は、インストール時のログです。python311envというディレクトリにtigramite-masterを置いてインストールしています。

(base) UsernoMacBook-Air:python311env username$ cd tigramite-master/
(base) UsernoMacBook-Air:tigramite-master username$ ls
FUNDING.yml		environment_py3.yml	neurips2020		tests
README.md		gui			setup.cfg		tigramite
docs			license.txt		setup.py		tutorials
(base) UsernoMacBook-Air:tigramite-master username$ python setup.py install
/Users/username/anaconda3/lib/python3.10/site-packages/setuptools/dist.py:770: UserWarning: Usage of dash-separated 'description-file' will not be supported in future versions. Please use the underscore name 'description_file' instead
  warnings.warn(
running install
/Users/username/anaconda3/lib/python3.10/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
/Users/username/anaconda3/lib/python3.10/site-packages/setuptools/command/easy_install.py:144: EasyInstallDeprecationWarning: easy_install command is deprecated. Use build and pip and other standards-based tools.
  warnings.warn(
running bdist_egg
running egg_info
creating tigramite.egg-info
writing tigramite.egg-info/PKG-INFO
writing dependency_links to tigramite.egg-info/dependency_links.txt
writing requirements to tigramite.egg-info/requires.txt
writing top-level names to tigramite.egg-info/top_level.txt
writing manifest file 'tigramite.egg-info/SOURCES.txt'
reading manifest file 'tigramite.egg-info/SOURCES.txt'
writing manifest file 'tigramite.egg-info/SOURCES.txt'
installing library code to build/bdist.macosx-11.0-arm64/egg
running install_lib
running build_py
creating build
creating build/lib
creating build/lib/tigramite
copying tigramite/lpcmci.py -> build/lib/tigramite
copying tigramite/models.py -> build/lib/tigramite
copying tigramite/pcmci.py -> build/lib/tigramite
copying tigramite/plotting.py -> build/lib/tigramite
copying tigramite/__init__.py -> build/lib/tigramite
copying tigramite/rpcmci.py -> build/lib/tigramite
copying tigramite/causal_effects.py -> build/lib/tigramite
copying tigramite/data_processing.py -> build/lib/tigramite
copying tigramite/pcmci_base.py -> build/lib/tigramite
creating build/lib/tigramite/independence_tests
copying tigramite/independence_tests/robust_parcorr.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/gsquared.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/independence_tests_base.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/__init__.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/parcorr_mult.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/parcorr.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/LBFGS.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/gpdc_torch.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/parcorr_wls.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/regressionCI.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/cmisymb.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/oracle_conditional_independence.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/cmiknn.py -> build/lib/tigramite/independence_tests
copying tigramite/independence_tests/gpdc.py -> build/lib/tigramite/independence_tests
creating build/lib/tigramite/toymodels
copying tigramite/toymodels/__init__.py -> build/lib/tigramite/toymodels
copying tigramite/toymodels/surrogate_generator.py -> build/lib/tigramite/toymodels
copying tigramite/toymodels/structural_causal_processes.py -> build/lib/tigramite/toymodels
creating build/bdist.macosx-11.0-arm64
creating build/bdist.macosx-11.0-arm64/egg
creating build/bdist.macosx-11.0-arm64/egg/tigramite
copying build/lib/tigramite/lpcmci.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
copying build/lib/tigramite/models.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
copying build/lib/tigramite/pcmci.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
copying build/lib/tigramite/plotting.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
copying build/lib/tigramite/__init__.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
copying build/lib/tigramite/rpcmci.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
copying build/lib/tigramite/causal_effects.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
creating build/bdist.macosx-11.0-arm64/egg/tigramite/toymodels
copying build/lib/tigramite/toymodels/__init__.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/toymodels
copying build/lib/tigramite/toymodels/surrogate_generator.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/toymodels
copying build/lib/tigramite/toymodels/structural_causal_processes.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/toymodels
copying build/lib/tigramite/data_processing.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
copying build/lib/tigramite/pcmci_base.py -> build/bdist.macosx-11.0-arm64/egg/tigramite
creating build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/robust_parcorr.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/gsquared.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/independence_tests_base.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/__init__.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/parcorr_mult.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/parcorr.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/LBFGS.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/gpdc_torch.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/parcorr_wls.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/regressionCI.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/cmisymb.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/oracle_conditional_independence.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/cmiknn.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
copying build/lib/tigramite/independence_tests/gpdc.py -> build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/lpcmci.py to lpcmci.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/models.py to models.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/pcmci.py to pcmci.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/plotting.py to plotting.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/__init__.py to __init__.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/rpcmci.py to rpcmci.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/causal_effects.py to causal_effects.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/toymodels/__init__.py to __init__.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/toymodels/surrogate_generator.py to surrogate_generator.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/toymodels/structural_causal_processes.py to structural_causal_processes.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/data_processing.py to data_processing.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/pcmci_base.py to pcmci_base.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/robust_parcorr.py to robust_parcorr.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/gsquared.py to gsquared.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/independence_tests_base.py to independence_tests_base.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/__init__.py to __init__.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/parcorr_mult.py to parcorr_mult.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/parcorr.py to parcorr.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/LBFGS.py to LBFGS.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/gpdc_torch.py to gpdc_torch.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/parcorr_wls.py to parcorr_wls.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/regressionCI.py to regressionCI.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/cmisymb.py to cmisymb.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/oracle_conditional_independence.py to oracle_conditional_independence.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/cmiknn.py to cmiknn.cpython-310.pyc
byte-compiling build/bdist.macosx-11.0-arm64/egg/tigramite/independence_tests/gpdc.py to gpdc.cpython-310.pyc
creating build/bdist.macosx-11.0-arm64/egg/EGG-INFO
copying tigramite.egg-info/PKG-INFO -> build/bdist.macosx-11.0-arm64/egg/EGG-INFO
copying tigramite.egg-info/SOURCES.txt -> build/bdist.macosx-11.0-arm64/egg/EGG-INFO
copying tigramite.egg-info/dependency_links.txt -> build/bdist.macosx-11.0-arm64/egg/EGG-INFO
copying tigramite.egg-info/requires.txt -> build/bdist.macosx-11.0-arm64/egg/EGG-INFO
copying tigramite.egg-info/top_level.txt -> build/bdist.macosx-11.0-arm64/egg/EGG-INFO
zip_safe flag not set; analyzing archive contents...
creating dist
creating 'dist/tigramite-5.2.1.18-py3.10.egg' and adding 'build/bdist.macosx-11.0-arm64/egg' to it
removing 'build/bdist.macosx-11.0-arm64/egg' (and everything under it)
Processing tigramite-5.2.1.18-py3.10.egg
Copying tigramite-5.2.1.18-py3.10.egg to /Users/username/anaconda3/lib/python3.10/site-packages
Adding tigramite 5.2.1.18 to easy-install.pth file

Installed /Users/username/anaconda3/lib/python3.10/site-packages/tigramite-5.2.1.18-py3.10.egg
Processing dependencies for tigramite==5.2.1.18
Searching for six==1.16.0
Best match: six 1.16.0
Adding six 1.16.0 to easy-install.pth file

Using /Users/username/anaconda3/lib/python3.10/site-packages
Searching for numba==0.56.4
Best match: numba 0.56.4
Adding numba 0.56.4 to easy-install.pth file

Using /Users/username/anaconda3/lib/python3.10/site-packages
Searching for scipy==1.10.0
Best match: scipy 1.10.0
Adding scipy 1.10.0 to easy-install.pth file

Using /Users/username/anaconda3/lib/python3.10/site-packages
Searching for numpy==1.22.3
Best match: numpy 1.22.3
Adding numpy 1.22.3 to easy-install.pth file
Installing f2py script to /Users/username/anaconda3/bin
Installing f2py3 script to /Users/username/anaconda3/bin
Installing f2py3.10 script to /Users/username/anaconda3/bin

Using /Users/username/anaconda3/lib/python3.10/site-packages
Searching for setuptools==65.6.3
Best match: setuptools 65.6.3
Adding setuptools 65.6.3 to easy-install.pth file

Using /Users/username/anaconda3/lib/python3.10/site-packages
Searching for llvmlite==0.39.1
Best match: llvmlite 0.39.1
Adding llvmlite 0.39.1 to easy-install.pth file

Using /Users/username/anaconda3/lib/python3.10/site-packages
Finished processing dependencies for tigramite==5.2.1.18

必要なPythonパッケージ

  • python=3.7-3.10
  • numpy: 1,18 <= numpy < 1.24
  • scipy: 1.10.0 <= scipy
  • numba == 0.56.4

サンプルコード

 以下の使用例を参照してください。Pearlの因果推論の例を実装してあります。

-Tigramite, スライド, ベイズ・確率プログラミング
-,