I am trying to implement the example from MBML Book in chapter two. The setup is that there are 22 test takers answering a 48 question test. The goal is to take the each person’s answers and find out which of 7 skills they likely have based on their responses (when we know which skills apply to each question). At the same time, you also need to model the probability of how hard it is to guess the answer to each of the 48 questions.
My code is sampling distributions using 1 dimensional tensors and some of the tensor lengths are different. For example
guess_probs = pyro.sample('guess_prob', dist.Beta(torch.ones(48)*2.5, torch.ones(48)*7.5))
skills = [pyro.sample('skill'+str(x), dist.Bernoulli(torch.ones(22) * 0.5)).int() for x in range(0, 7)]
The tensors for the probability of a person having each skill is of length 22, one for each person for that particular skill, but the variable I am sampling for the guess probabilities is of length 48, one for each question. I am getting an error from inside the step function of the pyro.infer.SVI object:
/usr/local/lib/python3.6/site-packages/pyro/infer/trace_elbo.py in _compute_log_r(model_trace, guide_trace) 20 if not model_site["is_observed"]: 21 log_r_term = log_r_term - guide_trace.nodes[name]["log_prob"] ---> 22 log_r.add((stacks[name], log_r_term.detach())) 23 return log_r 24 /usr/local/lib/python3.6/site-packages/pyro/infer/util.py in add(self, *items) 113 assert all(f.dim < 0 and -len(value.shape) <= f.dim for f in frames) 114 if frames in self: --> 115 self[frames] = self[frames] + value 116 else: 117 self[frames] = value RuntimeError: The size of tensor a (48) must match the size of tensor b (22) at non-singleton dimension 1
Is there a restriction that all pyro.param or pyro.sample statements must sample tensors of the same length?
I am also interested in whether using SVI to solve this type of problem is a workable approach- from some of the other threads I gather that there could be an issue with working with so many discrete variables.