# Mass matrix contains zeros on the diagonal

Hi. I am working on paper on post inference prior swapping to predict the year of song using bayesian linear regression.
Initially i am using prior as normal model and trying to compute posterior based on the data.

‘Year ~ F1 + F6 + F3 + F63 + F40 + F7’ . This are the features.

# Context for the model

with pm.Model() as normal_model:
# The prior for the model parameters will be a normal distribution
family = pm.glm.families.Normal()
# Creating the model requires a formula and data (and optionally a family)
pm.GLM.from_formula(formula, data = X_train, family = family)
# Perform Markov Chain Monte Carlo sampling
normal_trace = pm.sample(draws=2000, chains = 10)
The X_train data size is 463715.
As per the paper post inference prior swapping they have given the following
Our first set of experiments are on Bayesian linear regression models, which we can write as yi = Xiθ) N (0, σ2)
I am getting the following error when i run the model
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `sd_log__`.ravel()[0] is zero.
The derivative of RV `F7`.ravel()[0] is zero.
The derivative of RV `F40`.ravel()[0] is zero.
The derivative of RV `F63`.ravel()[0] is zero.
The derivative of RV `F3`.ravel()[0] is zero.
The derivative of RV `F6`.ravel()[0] is zero.
The derivative of RV `F1`.ravel()[0] is zero.
The derivative of RV `Intercept`.ravel()[0] is zero.

Hi,
Can you tell us what your version od PyMC3 is please? In particular, did you install the master branch?

this is what i installed
pip install git+https://github.com/pymc-devs/pymc3

Yeah that’s what I thought: something made initialization much more sensitive on the master branch, causing `ValueError: Mass matrix contains zeros on the diagonal` to appear more frequently.

• On this version, can you try:
• `normal_trace = pm.sample(init="adapt_diag")`
• More informative priors. I think the GLM module uses flat priors.
• If this still doesn’t work, try running exactly the same model, but on PyMC 3.8 (stable version).

CC @junpenglao @rpgoldman, as per our discussion on GH.

2 Likes

it solved the problem. but after completion, i am getting error - your session crashed after using all available RAM. i am using google colab. The maximum RAM allocated is 25 GB

Can you be more specific about what solved your problem please: was it specifying `adapt_diag` or downgrading to PyMC 3.8?