我试图在pymc3中使用多维变量来描述一个共有一个共同因子的4个变量的系统。也许我正在考虑这个错误,但是当我设置模型时,我不断从pymc3获得有关输入维度不匹配的错误。我尝试了几种变化无济于事。如何使用pymc3的形状参数来描述一个由4个观察变量组成的系统,其结构共享一个共同的观察变量?
import pymc3
import numpy
# Simulate some data
shared_obs = numpy.random.normal(0., 0.25, 1000)
indiv_obs = numpy.random.normal(0.1, 0.5, 1000)
# Build a model
with pymc3.Model():
shared_mu = pymc3.Uniform('shared_mu', -0.5, 0.5)
shared_sigma = pymc3.Lognormal('shared_sigma', 0.1, 1.)
shared = pymc3.Normal('shared', mu=shared_mu, sd=shared_sigma, observed=shared_obs)
a = pymc3.Uniform('a', -1., 1., shape=4)
B = pymc3.Uniform('B', -1., 1., shape=4)
sigma = pymc3.Lognormal('sigma', 0.1, 1., shape=4)
indiv = pymc3.Normal('indiv', mu=a + B*shared, sd = sigma, observed=indiv_obs, shape=4)
ValueError Traceback(最近一次调用 最后)in() 6 B = pymc3.Uniform(' B',-1。,1.,shape = 4) 7 sigma = pymc3.Lognormal(' sigma',0.1,1。,shape = 4) ----> 8 indiv = pymc3.Normal(' indiv',mu = a + B * shared,sd = sigma,observed = indiv_obs,shape = 4)
C:\ Program Files \ Anaconda3 \ lib \ site-packages \ theano \ tensor \ var.py in mul (自我,其他) 160#和那种情况下的返回值 161尝试: - > 162返回theano.tensor.mul(self,other) 除了(NotImplementedError,AsTensorError)之外的163: 164返回NotImplemented
C:\ Program Files \ Anaconda3 \ lib \ site-packages \ theano \ gof \ op.py in 致电(自我,*输入,** kwargs) 666 thunk.outputs = [storage_map [v] for node in node.outputs] 667 - > 668 required = thunk() 669断言不需要#我们提供了所有输入 670
C:\ Program Files \ Anaconda3 \ lib \ site-packages \ theano \ gof \ op.py in RVAL() 881 882 def rval(): - > 883 fill_storage() node.outputs中的o为884: 885 compute_map [o] [0] = True
C:\ Program Files \ Anaconda3 \ lib \ site-packages \ theano \ gof \ cc.py in 致电(自我)1705打印(self.error_storage,file = sys.stderr)1706加注 - > 1707再加注(exc_type,exc_value,exc_trace)1708 1709
C:\ Program Files \ Anaconda3 \ lib \ site-packages \ six.py reraise(tp, 价值,tb) 684如果值。追溯不是tb: 685提高value.with_traceback(tb) - > 686提高价值 687 688其他:
ValueError:输入维度不匹配。 (输入[0] .shape [0] = 4, 输入[1] .shape [0] = 1000)
答案 0 :(得分:0)
*
是逐元素乘法。如果您想要外部产品,可以使用
B[None, :] * shared[:, None]