2017-08-08 88 views
2

我試圖通過延伸的第一示例來運行具有兩個功能的高斯過程迴歸在https://pymc-devs.github.io/pymc3/notebooks/GP-introduction.htmlpymc3多個高斯過程迴歸

n = 20 
X = np.array([list(a) for a in zip(np.sort(3*np.random.rand(n)), np.sort(3*np.random.rand(n)))]) 
y = np.random.normal(size=n) 

with pm.Model() as model: 
    # priors on the covariance function hyperparameters 
    l = np.array([pm.Uniform('l1', 0, 10), pm.Uniform('l2', 0, 10)]) 

    # uninformative prior on the function variance 
    log_s2_f = pm.Uniform('log_s2_f', lower=-10, upper=5) 
    s2_f = pm.Deterministic('s2_f', tt.exp(log_s2_f)) 

    # uninformative prior on the noise variance 
    log_s2_n = pm.Uniform('log_s2_n', lower=-10, upper=5) 
    s2_n = pm.Deterministic('s2_n', tt.exp(log_s2_n)) 

    # covariance functions for the function f and the noise 
    f_cov = s2_f * pm.gp.cov.ExpQuad(input_dim=2, lengthscales=l) 

    y_obs = pm.gp.GP('y_obs', cov_func=f_cov, sigma=s2_n, observed={'X':X, 'Y':y}) 

這裏X輸入和y是用於測試的輸入的形狀。 當我運行代碼,我得到一個theano AsTensorError錯誤,被追蹤到這pymc3

/usr/local/lib/python2.7/site-packages/pymc3/gp/cov.pyc in square_dist(self, X, Z) 
    124 
    125  def square_dist(self, X, Z): 
--> 126   X = tt.mul(X, 1.0/self.lengthscales) 
    127   Xs = tt.sum(tt.square(X), 1) 
    128   if Z is None: 

是否有可能在pymc3運行多個高斯迴歸?如果是這樣,我相信我已經在某個地方弄亂了尺寸。

回答

1

我在下面的博客中發現了我的問題的解決方案,顯然這是pymc3的參考點。

https://discourse.pymc.io/t/multidimensional-input-using-gaussian-process/128

而不是定義的協方差作爲先驗分佈的陣列,它們被定義爲與部件的相應數量的多項分佈。通過更改上面的代碼行以上一切正常按預期工作

with pm.Model() as model: 
    # priors on the covariance function hyperparameters 
    l = pm.Gamma('l', 1, 1, shape=2)