How do I avoid unused parameters in NumPyro model?

I want to estimate the scores of 10 students in 4 tests.

The relationship between students to tests is many to many, but

  1. There are students who have not taken some of the tests — so for these students, it doesn’t make sense to have a sample site for the tests they have not taken

Basically, for every test, the number of students who have taken that test is not always equal to 10.

When I used a nested plate notation, I get a total of 40 parameters, among which many are unused and their estimates are corrupting the (multi-level) hyperprior estimates.

How can I avoid these unused parameters from being estimated by the model?

Ideally, my parameter array would be a 2d list of lists.

I’d suggest using a sparse representation for your parameter array to avoid estimating unused parameters in ur model/ Since not all students have taken all tests, you can represent ur data using a sparce matrix or a dictionary of dictionaries, where the keys represent the students and tests, and the values represent the corresponding scores.
here an ex.

scores = {
‘student1’: {‘test1’: 85, ‘test3’: 92}, ‘student2’: {‘test2’: 78, ‘test4’: 95}, # … and so on}

1 Like

Hi @maudeads

My data actually kind of looks like this

data = {
‘student1’: {‘test1’: a_11, ‘test3’: a_13}, ‘student2’: {‘test2’: a_22, ‘test4’: a_24}, …}

where each a_ij are 1D numpy arrays of size 100 (we can think of these arrays as some sort of attributes, for eg, first element could represent how many hours of lectures did the student attend for that particular test)

Right now, in numpyro, I do something like this:

with numpyro.plate("tests", n_ tests, dim=-1):
    mean_score = numpyro.sample("mean_score", dist.Normal(50, 20))

    with numpyro.plate("students", n_students, dim=-2):
        score = numpyro.sample("score", dist.Normal(mean_score, 20))

But this will also define missing parameters like score_12 (score for student 1 and test 2). Since the unused parameters will have posterior hpdi which are very wide, these parameters will corrupt the posterior of mean_score for each test. For instance, mean_score_1 for test_1 will also be influenced by score_21 even though the second student did not take the first test.

Could you please tell me how I can change this code to use a dictionary like you mentioned

scores = {
‘student1’: {‘test1’: score_11, ‘test3’: score_13}, ‘student2’: {‘test2’: score_22, ‘test4’: score_24}, …}

to define only the required parameters?