狠狠撸

狠狠撸Share a Scribd company logo
1 Part 3
July 2, 2019
: https://courses.wshito.com/semi2/2019-bayes-AI
( ) 1 Part 3 July 2, 2019 1 / 17
Python pp.15–24
: ?
PyMC3
( ) 1 Part 3 July 2, 2019 2 / 17
: ?
: ?
Figure:
( ) 1 Part 3 July 2, 2019 3 / 17
: ?
?
( ) 1 Part 3 July 2, 2019 4 / 17
: ?
X
P ({X = k}) =
λke?λ
k!
λ > 0 intensity
E[X] = λ
V ar[X] = λ
( ) 1 Part 3 July 2, 2019 5 / 17
: ?
xt ~ Poisson(λ)
where λ =
?
?
?
λ1 for t < τ
λ2 for t ≥ τ
( ) 1 Part 3 July 2, 2019 6 / 17
: ?
P r(H|D) =
P r(D|H)P r(H)
P r(D)
∝ P r(D|H)P r(H)
f(θ|x) ∝ f(x|θ)f(θ)
? f(λ|x) ∝ f(x|λ)f(λ),
x
( ) 1 Part 3 July 2, 2019 7 / 17
: ?
λ λ1, λ2, τ
f(λ|x) ∝ f(x|λ)f(λ)
? f({λ1, λ2, τ}|x) ∝ f(x|{λ1, λ2, τ})f({λ1, λ2, τ})
= f(x|{λ1, λ2, τ})f(λ1)f(λ2)f(τ)
( ) 1 Part 3 July 2, 2019 8 / 17
: ?
f({λ1, λ2, τ}|x) ∝ f(x|{λ1, λ2, τ})f(λ1)f(λ2)f(τ)
: f(xt|{λ1, λ2, τ}) =
λxt e?λ
xt!
, where
?
?
?
λ1 for t < τ
λ2 for t ≥ τ
: f(τ) = DiscreteUniform(1, 70)
: f(λi) = eα for i = 1, 2
α = ( xt/N)?1
E[λ] = 1/α λ
( ) 1 Part 3 July 2, 2019 9 / 17
: ?
Stan
PyMC3
( ) 1 Part 3 July 2, 2019 10 / 17
: ?
PyMC3
General API Quickstart:
https://docs.pymc.io/notebooks/api_quickstart.html
with pm.Model()
observed
pm.Deterministic()
( ) 1 Part 3 July 2, 2019 11 / 17
: ?
PyMC3
1
1 import numpy as np
2 import pymc3 as pm
3
4 count_data = np.loadtxt("data/txtdata.csv")
5
6 n_count_data = len(count_data)
7 alpha = 1.0 / count_data.mean()
8 idx = np.arange(n_count_data) # 0 n_count_data-1 index
9
10 with pm.Model() as model: #
11 lambda_1 = pm.Exponential("lambda_1", alpha)
12 lambda_2 = pm.Exponential("lambda_2", alpha)
13 tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data)
14 lambda_ = pm.math.switch(tau >= idx, lambda_1, lambda_2)
15 obs = pm.Poisson("obs", lambda_, observed=count_data)
16
17 with model:
18 trace = pm.sample(40000) #
( ) 1 Part 3 July 2, 2019 12 / 17
: ?
2
with pm.Model() as model:
#
lambda_1 = pm.Exponential("lambda_1", alpha)
lambda_2 = pm.Exponential("lambda_2", alpha)
tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data)
# idx lambda
lambda_ = pm.math.switch(tau >= idx, lambda_1, lambda_2)
#
obs = pm.Poisson("obs", lambda_, observed=count_data)
( ) 1 Part 3 July 2, 2019 13 / 17
: ?
pm.model_to_graphviz(model)
74
tau ~ DiscreteUniform
obs ~ Poisson
lambda_2 ~ Exponential lambda_1 ~ Exponential
( ) 1 Part 3 July 2, 2019 14 / 17
: ?
pm.traceplot(trace)
( ) 1 Part 3 July 2, 2019 15 / 17
: ?
pm.plot_posterior(trace)
( ) 1 Part 3 July 2, 2019 16 / 17
: ?
pm.summary(trace)
( ) 1 Part 3 July 2, 2019 17 / 17
Ad

Recommended

Ads final report - Team 8
Ads final report - Team 8
kvignesh92
?
Q&a
Q&a
Subhabrata Mishra
?
Write a program to create a linear linked list interactively and print out th...
Write a program to create a linear linked list interactively and print out th...
hwbloom56
?
Time Series Made Easy
Time Series Made Easy
Sameh BEN FREDJ
?
Pycon2017
Pycon2017
Yuta Kashino
?
ベイジアンディープニューラルネット
ベイジアンディープニューラルネット
Yuta Kashino
?
Introduction to Bayesian Analysis in Python
Introduction to Bayesian Analysis in Python
Peadar Coyle
?
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
QMC Program: Trends and Advances in Monte Carlo Sampling Algorithms Workshop,...
The Statistical and Applied Mathematical Sciences Institute
?
Into to prob_prog_hari (2)
Into to prob_prog_hari (2)
Hariharan Chandrasekaran
?
Machine Learning Algorithms Review(Part 2)
Machine Learning Algorithms Review(Part 2)
Zihui Li
?
bayes_machine_learning_book for data scientist
bayes_machine_learning_book for data scientist
addamare554
?
Bayesian Neural Networks
Bayesian Neural Networks
Natan Katz
?
Introduction to Machine Learning
Introduction to Machine Learning
Big_Data_Ukraine
?
机械学习モデルの判断根拠の説明
机械学习モデルの判断根拠の説明
Satoshi Hara
?
0-introduction.pdf
0-introduction.pdf
ArafathJazeeb1
?
. An introduction to machine learning and probabilistic ...
. An introduction to machine learning and probabilistic ...
butest
?
Maxwell W Libbrecht - pomegranate: fast and flexible probabilistic modeling i...
Maxwell W Libbrecht - pomegranate: fast and flexible probabilistic modeling i...
PyData
?
Bayesianmd2
Bayesianmd2
GuangYang92
?
DarwicheUAI00.ppt
DarwicheUAI00.ppt
AntonyJaison3
?
2018 MUMS Fall Course - Introduction to statistical and mathematical model un...
2018 MUMS Fall Course - Introduction to statistical and mathematical model un...
The Statistical and Applied Mathematical Sciences Institute
?
Lecture12 xing
Lecture12 xing
Tianlu Wang
?
Learning stochastic neural networks with Chainer
Learning stochastic neural networks with Chainer
Seiya Tokui
?
深层学习とベイズ统计
深层学习とベイズ统计
Yuta Kashino
?
Section6 stochastic
Section6 stochastic
cairo university
?
Machine Learning With MapReduce, K-Means, MLE
Machine Learning With MapReduce, K-Means, MLE
Jason J Pulikkottil
?
Animashree Anandkumar, Electrical Engineering and CS Dept, UC Irvine at MLcon...
Animashree Anandkumar, Electrical Engineering and CS Dept, UC Irvine at MLcon...
MLconf
?
Striving to Demystify Bayesian Computational Modelling
Striving to Demystify Bayesian Computational Modelling
Marco Wirthlin
?
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
AminaRepo
?
第3章 遅延学習---最近傍法を使った分類
第3章 遅延学習---最近傍法を使った分類
Wataru Shito
?
統計的推定の基礎 2 -- 分散の推定
統計的推定の基礎 2 -- 分散の推定
Wataru Shito
?

More Related Content

Similar to 2019年 演習II.第1章 ベイズ推論の考え方 Part 3 (20)

Into to prob_prog_hari (2)
Into to prob_prog_hari (2)
Hariharan Chandrasekaran
?
Machine Learning Algorithms Review(Part 2)
Machine Learning Algorithms Review(Part 2)
Zihui Li
?
bayes_machine_learning_book for data scientist
bayes_machine_learning_book for data scientist
addamare554
?
Bayesian Neural Networks
Bayesian Neural Networks
Natan Katz
?
Introduction to Machine Learning
Introduction to Machine Learning
Big_Data_Ukraine
?
机械学习モデルの判断根拠の説明
机械学习モデルの判断根拠の説明
Satoshi Hara
?
0-introduction.pdf
0-introduction.pdf
ArafathJazeeb1
?
. An introduction to machine learning and probabilistic ...
. An introduction to machine learning and probabilistic ...
butest
?
Maxwell W Libbrecht - pomegranate: fast and flexible probabilistic modeling i...
Maxwell W Libbrecht - pomegranate: fast and flexible probabilistic modeling i...
PyData
?
Bayesianmd2
Bayesianmd2
GuangYang92
?
DarwicheUAI00.ppt
DarwicheUAI00.ppt
AntonyJaison3
?
2018 MUMS Fall Course - Introduction to statistical and mathematical model un...
2018 MUMS Fall Course - Introduction to statistical and mathematical model un...
The Statistical and Applied Mathematical Sciences Institute
?
Lecture12 xing
Lecture12 xing
Tianlu Wang
?
Learning stochastic neural networks with Chainer
Learning stochastic neural networks with Chainer
Seiya Tokui
?
深层学习とベイズ统计
深层学习とベイズ统计
Yuta Kashino
?
Section6 stochastic
Section6 stochastic
cairo university
?
Machine Learning With MapReduce, K-Means, MLE
Machine Learning With MapReduce, K-Means, MLE
Jason J Pulikkottil
?
Animashree Anandkumar, Electrical Engineering and CS Dept, UC Irvine at MLcon...
Animashree Anandkumar, Electrical Engineering and CS Dept, UC Irvine at MLcon...
MLconf
?
Striving to Demystify Bayesian Computational Modelling
Striving to Demystify Bayesian Computational Modelling
Marco Wirthlin
?
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
AminaRepo
?
Machine Learning Algorithms Review(Part 2)
Machine Learning Algorithms Review(Part 2)
Zihui Li
?
bayes_machine_learning_book for data scientist
bayes_machine_learning_book for data scientist
addamare554
?
Bayesian Neural Networks
Bayesian Neural Networks
Natan Katz
?
Introduction to Machine Learning
Introduction to Machine Learning
Big_Data_Ukraine
?
机械学习モデルの判断根拠の説明
机械学习モデルの判断根拠の説明
Satoshi Hara
?
. An introduction to machine learning and probabilistic ...
. An introduction to machine learning and probabilistic ...
butest
?
Maxwell W Libbrecht - pomegranate: fast and flexible probabilistic modeling i...
Maxwell W Libbrecht - pomegranate: fast and flexible probabilistic modeling i...
PyData
?
Learning stochastic neural networks with Chainer
Learning stochastic neural networks with Chainer
Seiya Tokui
?
深层学习とベイズ统计
深层学习とベイズ统计
Yuta Kashino
?
Machine Learning With MapReduce, K-Means, MLE
Machine Learning With MapReduce, K-Means, MLE
Jason J Pulikkottil
?
Animashree Anandkumar, Electrical Engineering and CS Dept, UC Irvine at MLcon...
Animashree Anandkumar, Electrical Engineering and CS Dept, UC Irvine at MLcon...
MLconf
?
Striving to Demystify Bayesian Computational Modelling
Striving to Demystify Bayesian Computational Modelling
Marco Wirthlin
?
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
Aaa ped-23-Artificial Neural Network: Keras and Tensorfow
AminaRepo
?

More from Wataru Shito (20)

第3章 遅延学習---最近傍法を使った分類
第3章 遅延学習---最近傍法を使った分類
Wataru Shito
?
統計的推定の基礎 2 -- 分散の推定
統計的推定の基礎 2 -- 分散の推定
Wataru Shito
?
統計的推定の基礎 1 -- 期待値の推定
統計的推定の基礎 1 -- 期待値の推定
Wataru Shito
?
第4章 確率的学習---単純ベイズを使った分類
第4章 確率的学習---単純ベイズを使った分類
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 3.講義ノート
演習II.第1章 ベイズ推論の考え方 Part 3.講義ノート
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 3.スライド
演習II.第1章 ベイズ推論の考え方 Part 3.スライド
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 2.講義ノート
演習II.第1章 ベイズ推論の考え方 Part 2.講義ノート
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 2.スライド
演習II.第1章 ベイズ推論の考え方 Part 2.スライド
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 1.講義ノート
演習II.第1章 ベイズ推論の考え方 Part 1.講義ノート
Wataru Shito
?
マクロ経済学I 「第8章 総需要?総供給分析(AD-AS分析)」
マクロ経済学I 「第8章 総需要?総供給分析(AD-AS分析)」
Wataru Shito
?
経済数学II 「第9章 最適化(Optimization)」
経済数学II 「第9章 最適化(Optimization)」
Wataru Shito
?
マクロ経済学I 「第10章 総需要 II.IS-LM分析とAD曲線」
マクロ経済学I 「第10章 総需要 II.IS-LM分析とAD曲線」
Wataru Shito
?
第9回 大規模データを用いたデータフレーム操作実習(3)
第9回 大規模データを用いたデータフレーム操作実習(3)
Wataru Shito
?
第8回 大規模データを用いたデータフレーム操作実習(2)
第8回 大規模データを用いたデータフレーム操作実習(2)
Wataru Shito
?
経済数学II 「第12章 制約つき最適化」
Wataru Shito
?
マクロ経済学I 「第9章 総需要 I」
マクロ経済学I 「第9章 総需要 I」
Wataru Shito
?
経済数学II 「第11章 選択変数が2個以上の場合の最適化」
経済数学II 「第11章 選択変数が2個以上の場合の最適化」
Wataru Shito
?
マクロ経済学I 「第6章 開放経済の長期分析」
マクロ経済学I 「第6章 開放経済の長期分析」
Wataru Shito
?
経済数学II 「第8章 一般関数型モデルの比較静学」
Wataru Shito
?
マクロ経済学I 「第4,5章 貨幣とインフレーション」
Wataru Shito
?
第3章 遅延学習---最近傍法を使った分類
第3章 遅延学習---最近傍法を使った分類
Wataru Shito
?
統計的推定の基礎 2 -- 分散の推定
統計的推定の基礎 2 -- 分散の推定
Wataru Shito
?
統計的推定の基礎 1 -- 期待値の推定
統計的推定の基礎 1 -- 期待値の推定
Wataru Shito
?
第4章 確率的学習---単純ベイズを使った分類
第4章 確率的学習---単純ベイズを使った分類
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 3.講義ノート
演習II.第1章 ベイズ推論の考え方 Part 3.講義ノート
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 3.スライド
演習II.第1章 ベイズ推論の考え方 Part 3.スライド
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 2.講義ノート
演習II.第1章 ベイズ推論の考え方 Part 2.講義ノート
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 2.スライド
演習II.第1章 ベイズ推論の考え方 Part 2.スライド
Wataru Shito
?
演習II.第1章 ベイズ推論の考え方 Part 1.講義ノート
演習II.第1章 ベイズ推論の考え方 Part 1.講義ノート
Wataru Shito
?
マクロ経済学I 「第8章 総需要?総供給分析(AD-AS分析)」
マクロ経済学I 「第8章 総需要?総供給分析(AD-AS分析)」
Wataru Shito
?
経済数学II 「第9章 最適化(Optimization)」
経済数学II 「第9章 最適化(Optimization)」
Wataru Shito
?
マクロ経済学I 「第10章 総需要 II.IS-LM分析とAD曲線」
マクロ経済学I 「第10章 総需要 II.IS-LM分析とAD曲線」
Wataru Shito
?
第9回 大規模データを用いたデータフレーム操作実習(3)
第9回 大規模データを用いたデータフレーム操作実習(3)
Wataru Shito
?
第8回 大規模データを用いたデータフレーム操作実習(2)
第8回 大規模データを用いたデータフレーム操作実習(2)
Wataru Shito
?
経済数学II 「第12章 制約つき最適化」
Wataru Shito
?
マクロ経済学I 「第9章 総需要 I」
マクロ経済学I 「第9章 総需要 I」
Wataru Shito
?
経済数学II 「第11章 選択変数が2個以上の場合の最適化」
経済数学II 「第11章 選択変数が2個以上の場合の最適化」
Wataru Shito
?
マクロ経済学I 「第6章 開放経済の長期分析」
マクロ経済学I 「第6章 開放経済の長期分析」
Wataru Shito
?
経済数学II 「第8章 一般関数型モデルの比較静学」
Wataru Shito
?
マクロ経済学I 「第4,5章 貨幣とインフレーション」
Wataru Shito
?
Ad

Recently uploaded (20)

最新版美国芝加哥大学毕业证(鲍颁丑颈肠补驳辞毕业证书)原版定制
最新版美国芝加哥大学毕业证(鲍颁丑颈肠补驳辞毕业证书)原版定制
taqyea
?
Camuflaje Tipos Características Militar 2025.ppt
Camuflaje Tipos Características Militar 2025.ppt
e58650738
?
reporting monthly for genset & Air Compressor.pptx
reporting monthly for genset & Air Compressor.pptx
dacripapanjaitan
?
最新版美国佐治亚大学毕业证(鲍骋础毕业证书)原版定制
最新版美国佐治亚大学毕业证(鲍骋础毕业证书)原版定制
Taqyea
?
Model Evaluation & Visualisation part of a series of intro modules for data ...
Model Evaluation & Visualisation part of a series of intro modules for data ...
brandonlee626749
?
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
CristineGraceAcuyan
?
Attendance Presentation Project Excel.pptx
Attendance Presentation Project Excel.pptx
s2025266191
?
一比一原版(罢鲍颁毕业证书)开姆尼茨工业大学毕业证如何办理
一比一原版(罢鲍颁毕业证书)开姆尼茨工业大学毕业证如何办理
taqyed
?
定制翱颁础顿学生卡加拿大安大略艺术与设计大学成绩单范本,翱颁础顿成绩单复刻
定制翱颁础顿学生卡加拿大安大略艺术与设计大学成绩单范本,翱颁础顿成绩单复刻
taqyed
?
The Influence off Flexible Work Policies
The Influence off Flexible Work Policies
sales480687
?
llm_presentation and deep learning methods
llm_presentation and deep learning methods
sayedabdussalam11
?
25 items quiz for practical research 1 in grade 11
25 items quiz for practical research 1 in grade 11
leamaydayaganon81
?
Residential Zone 4 for industrial village
Residential Zone 4 for industrial village
MdYasinArafat13
?
最新版美国约翰霍普金斯大学毕业证(闯贬鲍毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(闯贬鲍毕业证书)原版定制
Taqyea
?
Shifting Focus on AI: How it Can Make a Positive Difference
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
?
presentation4.pdf Intro to mcmc methodss
presentation4.pdf Intro to mcmc methodss
SergeyTsygankov6
?
Indigo_Airlines_Strategy_Presentation.pptx
Indigo_Airlines_Strategy_Presentation.pptx
mukeshpurohit991
?
deep_learning_presentation related to llm
deep_learning_presentation related to llm
sayedabdussalam11
?
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
?
ppt somu_Jarvis_AI_Assistant_presen.pptx
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
?
最新版美国芝加哥大学毕业证(鲍颁丑颈肠补驳辞毕业证书)原版定制
最新版美国芝加哥大学毕业证(鲍颁丑颈肠补驳辞毕业证书)原版定制
taqyea
?
Camuflaje Tipos Características Militar 2025.ppt
Camuflaje Tipos Características Militar 2025.ppt
e58650738
?
reporting monthly for genset & Air Compressor.pptx
reporting monthly for genset & Air Compressor.pptx
dacripapanjaitan
?
最新版美国佐治亚大学毕业证(鲍骋础毕业证书)原版定制
最新版美国佐治亚大学毕业证(鲍骋础毕业证书)原版定制
Taqyea
?
Model Evaluation & Visualisation part of a series of intro modules for data ...
Model Evaluation & Visualisation part of a series of intro modules for data ...
brandonlee626749
?
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
624753984-Annex-A3-RPMS-Tool-for-Proficient-Teachers-SY-2024-2025.pdf
CristineGraceAcuyan
?
Attendance Presentation Project Excel.pptx
Attendance Presentation Project Excel.pptx
s2025266191
?
一比一原版(罢鲍颁毕业证书)开姆尼茨工业大学毕业证如何办理
一比一原版(罢鲍颁毕业证书)开姆尼茨工业大学毕业证如何办理
taqyed
?
定制翱颁础顿学生卡加拿大安大略艺术与设计大学成绩单范本,翱颁础顿成绩单复刻
定制翱颁础顿学生卡加拿大安大略艺术与设计大学成绩单范本,翱颁础顿成绩单复刻
taqyed
?
The Influence off Flexible Work Policies
The Influence off Flexible Work Policies
sales480687
?
llm_presentation and deep learning methods
llm_presentation and deep learning methods
sayedabdussalam11
?
25 items quiz for practical research 1 in grade 11
25 items quiz for practical research 1 in grade 11
leamaydayaganon81
?
Residential Zone 4 for industrial village
Residential Zone 4 for industrial village
MdYasinArafat13
?
最新版美国约翰霍普金斯大学毕业证(闯贬鲍毕业证书)原版定制
最新版美国约翰霍普金斯大学毕业证(闯贬鲍毕业证书)原版定制
Taqyea
?
Shifting Focus on AI: How it Can Make a Positive Difference
Shifting Focus on AI: How it Can Make a Positive Difference
1508 A/S
?
presentation4.pdf Intro to mcmc methodss
presentation4.pdf Intro to mcmc methodss
SergeyTsygankov6
?
Indigo_Airlines_Strategy_Presentation.pptx
Indigo_Airlines_Strategy_Presentation.pptx
mukeshpurohit991
?
deep_learning_presentation related to llm
deep_learning_presentation related to llm
sayedabdussalam11
?
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Prescriptive Process Monitoring Under Uncertainty and Resource Constraints: A...
Mahmoud Shoush
?
ppt somu_Jarvis_AI_Assistant_presen.pptx
ppt somu_Jarvis_AI_Assistant_presen.pptx
MohammedumarFarhan
?
Ad

2019年 演習II.第1章 ベイズ推論の考え方 Part 3

  • 1. 1 Part 3 July 2, 2019 : https://courses.wshito.com/semi2/2019-bayes-AI ( ) 1 Part 3 July 2, 2019 1 / 17
  • 2. Python pp.15–24 : ? PyMC3 ( ) 1 Part 3 July 2, 2019 2 / 17
  • 3. : ? : ? Figure: ( ) 1 Part 3 July 2, 2019 3 / 17
  • 4. : ? ? ( ) 1 Part 3 July 2, 2019 4 / 17
  • 5. : ? X P ({X = k}) = λke?λ k! λ > 0 intensity E[X] = λ V ar[X] = λ ( ) 1 Part 3 July 2, 2019 5 / 17
  • 6. : ? xt ~ Poisson(λ) where λ = ? ? ? λ1 for t < τ λ2 for t ≥ τ ( ) 1 Part 3 July 2, 2019 6 / 17
  • 7. : ? P r(H|D) = P r(D|H)P r(H) P r(D) ∝ P r(D|H)P r(H) f(θ|x) ∝ f(x|θ)f(θ) ? f(λ|x) ∝ f(x|λ)f(λ), x ( ) 1 Part 3 July 2, 2019 7 / 17
  • 8. : ? λ λ1, λ2, τ f(λ|x) ∝ f(x|λ)f(λ) ? f({λ1, λ2, τ}|x) ∝ f(x|{λ1, λ2, τ})f({λ1, λ2, τ}) = f(x|{λ1, λ2, τ})f(λ1)f(λ2)f(τ) ( ) 1 Part 3 July 2, 2019 8 / 17
  • 9. : ? f({λ1, λ2, τ}|x) ∝ f(x|{λ1, λ2, τ})f(λ1)f(λ2)f(τ) : f(xt|{λ1, λ2, τ}) = λxt e?λ xt! , where ? ? ? λ1 for t < τ λ2 for t ≥ τ : f(τ) = DiscreteUniform(1, 70) : f(λi) = eα for i = 1, 2 α = ( xt/N)?1 E[λ] = 1/α λ ( ) 1 Part 3 July 2, 2019 9 / 17
  • 10. : ? Stan PyMC3 ( ) 1 Part 3 July 2, 2019 10 / 17
  • 11. : ? PyMC3 General API Quickstart: https://docs.pymc.io/notebooks/api_quickstart.html with pm.Model() observed pm.Deterministic() ( ) 1 Part 3 July 2, 2019 11 / 17
  • 12. : ? PyMC3 1 1 import numpy as np 2 import pymc3 as pm 3 4 count_data = np.loadtxt("data/txtdata.csv") 5 6 n_count_data = len(count_data) 7 alpha = 1.0 / count_data.mean() 8 idx = np.arange(n_count_data) # 0 n_count_data-1 index 9 10 with pm.Model() as model: # 11 lambda_1 = pm.Exponential("lambda_1", alpha) 12 lambda_2 = pm.Exponential("lambda_2", alpha) 13 tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data) 14 lambda_ = pm.math.switch(tau >= idx, lambda_1, lambda_2) 15 obs = pm.Poisson("obs", lambda_, observed=count_data) 16 17 with model: 18 trace = pm.sample(40000) # ( ) 1 Part 3 July 2, 2019 12 / 17
  • 13. : ? 2 with pm.Model() as model: # lambda_1 = pm.Exponential("lambda_1", alpha) lambda_2 = pm.Exponential("lambda_2", alpha) tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data) # idx lambda lambda_ = pm.math.switch(tau >= idx, lambda_1, lambda_2) # obs = pm.Poisson("obs", lambda_, observed=count_data) ( ) 1 Part 3 July 2, 2019 13 / 17
  • 14. : ? pm.model_to_graphviz(model) 74 tau ~ DiscreteUniform obs ~ Poisson lambda_2 ~ Exponential lambda_1 ~ Exponential ( ) 1 Part 3 July 2, 2019 14 / 17
  • 15. : ? pm.traceplot(trace) ( ) 1 Part 3 July 2, 2019 15 / 17
  • 16. : ? pm.plot_posterior(trace) ( ) 1 Part 3 July 2, 2019 16 / 17
  • 17. : ? pm.summary(trace) ( ) 1 Part 3 July 2, 2019 17 / 17