Pymc3 中的随机索引
Stochastic Indexing in Pymc3
我是 pymc3 的新手,我正在尝试了解如何以不同的方式将随机变量应用于模型。我想适合以下(设计的)模型,但我在文档中找不到任何支持。
![equation](https://latex.codecogs.com/gif.latex?%5Cbegin%7Balign*%7D%20y_%7Bt%7D%26%5Csim%5Cmathcal%7BN%7D%28%5Cmu_%7Bt%7D%2C%5Csigma%29%5C%20%5C%5C%20%5Cmu_t%26%3D%20%5Calpha+%5Cbeta%20y_%7Bt-%5Cgamma%7D%5C%20%5C%5C%20%5Calpha%26%5Csim%5Cmathcal%7BN%7D%280%2C1%29%5C%20%5C%5C%20%5Cbeta%26%5Csim%5Cmathcal%7BN%7D%280%2C1%29%5C%20%5C%5C%20%5Cgamma%26%5Csim%5Cmathrm%7BDiscreteUniform%7D%281%2C10%29%20%5Cend%7Balign*%7D)
我尝试了以下方法,但 numpy 不允许这样的索引:
seq = numpy.arange(10,y_train.size)
basic_model = pymc3.Model()
with basic_model:
alpha = pymc3.Normal('alpha',mu=0,sd=1)
beta = pymc3.Normal('beta',mu=0,sd=1)
gamma = pymc3.DiscreteUniform('gamma',lower=1,upper=10)
mu = pymc3.Deterministic('mu',alpha+beta*y_train[seq-gamma])
y = pymc3.Normal('y',mu=mu,sd=sigma,observed=y_train[11:])
map_estimate = pymc3.find_MAP(model=basic_model)
step = pymc3.Metropolis()
trace = pymc3.sample(10000,step,start=map_estimate,progressbar=True)
您需要先将 numpy 数组转换为 theano const:
tt.as_tensor_variable(y_train)[seq-gamma]
我是 pymc3 的新手,我正在尝试了解如何以不同的方式将随机变量应用于模型。我想适合以下(设计的)模型,但我在文档中找不到任何支持。
我尝试了以下方法,但 numpy 不允许这样的索引:
seq = numpy.arange(10,y_train.size)
basic_model = pymc3.Model()
with basic_model:
alpha = pymc3.Normal('alpha',mu=0,sd=1)
beta = pymc3.Normal('beta',mu=0,sd=1)
gamma = pymc3.DiscreteUniform('gamma',lower=1,upper=10)
mu = pymc3.Deterministic('mu',alpha+beta*y_train[seq-gamma])
y = pymc3.Normal('y',mu=mu,sd=sigma,observed=y_train[11:])
map_estimate = pymc3.find_MAP(model=basic_model)
step = pymc3.Metropolis()
trace = pymc3.sample(10000,step,start=map_estimate,progressbar=True)
您需要先将 numpy 数组转换为 theano const:
tt.as_tensor_variable(y_train)[seq-gamma]