Cholesky Factor Invariance and Traceplot Errors

I’m updating a model in Pymc 4 that follows the same basic structure of the Radon example. In my case, individuals are clusters and measurements are timepoints, i.e., a repeated measures design.

The covariance model (cell 40) runs without any issues; however, when requesting traceplots I get the following warnings:

arviz/stats/density_utils.py:491: UserWarning: Your data appears to have a single value or no finite values
arviz/stats/density_utils.py:706: RuntimeWarning: divide by zero encountered in true_divide f = grid_counts / bin_width / len(x)
arviz/stats/density_utils.py:709: RuntimeWarning: divide by zero encountered in double_scalars
  bw /= bin_width

Followed by a traceback that ends with:

File ~/miniconda3/envs/pymc4_env/lib/python3.9/site-packages/arviz/stats/density_utils.py:715, in _kde_convolution(x, bw, grid_edges, grid_counts, grid_len, bound_correction, **kwargs)
    711 # See: https://stackoverflow.com/questions/2773606/gaussian-filter-in-matlab
    713 grid = (grid_edges[1:] + grid_edges[:-1]) / 2
--> 715 kernel_n = int(bw * 2 * np.pi)
    716 if kernel_n == 0:
    717     kernel_n = 1

OverflowError: cannot convert float infinity to integer

The kde for the intercept-slope correlation will render but no traceplot is produced for the correlation, or any of the remaining parameters in the model.

I’m wondering if this is an issue with the constants that come out of pm.LKJCholeskyCov() distribution. I’m using arviz==0.12.0. I don’t encounter these problems when using pymc3==3.11.1 with arviz==0.11.2

2 Likes

Hi, if you can reproduce the issue with a simulated dataset (e.g. using samples from numpy.random and numpy.ones or something like that) it will be easier to track down the issue and address it. If you have inf or nans in the resulting samples I am not sure there is much that can be done. I will take a look too, but it will probably take a while until I get to it, and it will be longer if I have to both reproduce the issue first then see what is going on and how to fix it.

In the meantime, I think you should be able to use the indexing strategy from Label guide — ArviZ dev documentation (not necessarly the labeling too) to plot only the non-constant and finite variables.

I have the same issue.
As a workaround I plot the correlations separately and only the dimensions of interest:

az.plot_trace(trace, var_names=['chol_cov_corr'], filter_vars='like',
                       coords={"chol_cov_corr_dim_0": 0, "chol_cov_corr_dim_1": 1, })

It seems the problem is the constant ones on the diagonal going into the KDE what cause the problem.