나는 최근에 emcee
만 독점적으로 사용한 후 pymc3
을 학습하기 시작했으며 일부 개념적 문제가 발생합니다.pymc3의 다 변수 선형 회귀
제 7 장 Hogg's Fitting a model to data으로 연습하고 있습니다. 이것은 임의의 2 차원 불확실성을 갖는 직선에 대한 mcmc 피트를 포함한다. 나는 이것을 emcee
에서 아주 쉽게 수행했지만, pymc
이 나에게 몇 가지 문제를주고 있습니다.
본질적으로 다 변수 가우스 확률 (gaussian likelihood)을 사용하는 것으로 귀결됩니다.
여기까지 제가 지금까지 있습니다.
from pymc3 import *
import numpy as np
import matplotlib.pyplot as plt
size = 200
true_intercept = 1
true_slope = 2
true_x = np.linspace(0, 1, size)
# y = a + b*x
true_regression_line = true_intercept + true_slope * true_x
# add noise
# here the errors are all the same but the real world they are usually not!
std_y, std_x = 0.1, 0.1
y = true_regression_line + np.random.normal(scale=std_y, size=size)
x = true_x + np.random.normal(scale=std_x, size=size)
y_err = np.ones_like(y) * std_y
x_err = np.ones_like(x) * std_x
data = dict(x=x, y=y)
with Model() as model: # model specifications in PyMC3 are wrapped in a with-statement
# Define priors
intercept = Normal('Intercept', 0, sd=20)
gradient = Normal('gradient', 0, sd=20)
# Define likelihood
likelihood = MvNormal('y', mu=intercept + gradient * x,
tau=1./(np.stack((y_err, x_err))**2.), observed=y)
# start the mcmc!
start = find_MAP() # Find starting value by optimization
step = NUTS(scaling=start) # Instantiate MCMC sampling algorithm
trace = sample(2000, step, start=start, progressbar=False) # draw 2000 posterior samples using NUTS sampling
이
는 오류가 발생합니다 :LinAlgError: Last 2 dimensions of the array must be square
그래서 내가 MvNormal
x와 y에 대한 측정 값 (mu
들) 및 관련 측정 불확도 (y_err
및 x_err
)를 통과하기 위해 노력하고있어. 그러나 그것은 2d tau
인수를 좋아하지 않는 것으로 보입니다.
아이디어가 있으십니까? 이 가능해야한다
감사
모델에서''x''와''y'' 측정 오류를 포함하여 선형 회귀를하려고합니까? – aloctavodia
예 : 2d 불확실성 – Lucidnonsense