我在代码中破坏了变量形状时遇到麻烦。我正在尝试在pymc3中实现项目响应理论的一种变体,并且在将特定学生的多个观察值传递到模型中时遇到麻烦。
ability_shape = y_data.shape[0]
difficulty_shape = y_data.shape[1]
highlight_weight_shape = x_data.shape[1]
ability_idx = np.ravel(np.tile(np.arange(ability_shape),
(difficulty_shape,1)).T)
difficulty_idx = np.ravel(np.tile(np.arange(difficulty_shape),
(ability_shape,1)))
y_data = np.ravel(y_data)
with pm.Model() as model:
ability = pm.Normal('ability', mu=0, sd=1, shape=ability_shape)
difficulty = pm.Normal('difficulty', mu=0, sd=1, shape=difficulty_shape)
highlight_weight = pm.Normal('highlight_weight', mu=0, sd=1,
shape=highlight_weight_shape)
a= pm.math.dot(highlight_weight,x_data) #here is the problem
b = ability[ability_idx] - difficulty[difficulty_idx]
η = a + b
p= pm.Deterministic('p', pm.math.sigmoid(η))
y_obs = pm.Bernoulli('y_obs', p=p, observed=y_data)
trace = pm.sample(draws=2000, tune=2000, njobs=1)
如果我从x_data(即x_data [0])中明确为问题行添加一行,则我的代码运行良好。但是,我无法弄清楚每次如何传递适当的行。