Multivariate normal problem specifying sigma

Hi Nick/everyone,

I tried to implement the Hierarchical linear regression in general marginal formulation on the example model page. However, when I try to run the model (copied and pasted the code from the site) it produces this error:

Error: TensorFlow hit a numerical problem that caused it to error. greta can handle these as bad proposals if you rerun mcmc() with the argument one_by_one = TRUE. This will slow down the sampler slightly.

Error in py_call_impl(callable, dots$args, dots$keywords): InvalidArgumentError: Input matrix is not invertible.
[[node mcmc_sample_chain_1/trace_scan/while/smart_for_loop/while/mh_one_step/hmc_kernel_one_step/leapfrog_integrate/while/leapfrog_integrate_one_step/maybe_call_fn_and_grads/value_and_gradients/MultivariateNormalTriL/log_prob/affine_linear_operator/inverse/LinearOperatorLowerTriangular/solve/LinearOperatorLowerTriangular/solve/MatrixTriangularSolve/MatrixTriangularSolve (defined at \Users\Chris Baldock\Anaconda3\envs\r-reticulate\lib\site-packages\tensorflow_core\python\framework\ ]]

Original stack trace for 'mcmc_sample_chain_1/trace_scan/while/smart_for_loop/while/mh_one_step/hmc_kernel_one_step/leapfrog_integrate/while/leapfrog_integrate_one_step/maybe_

If I use one_by_one = true in the sampler, it gets through the warmup but then fails at sampling with this error:

Error in py_call_impl(callable, dots$args, dots$keywords): UnimplementedError: TensorArray has size zero, but element shape [?,3] is not fully defined. Currently only static shapes are supported when packing zero-size TensorArrays.
[[node mcmc_sample_chain_3/trace_scan/TensorArrayStack_9/TensorArrayGatherV3 (defined at \tensorflow_core\python\framework\ ]]

Original stack trace for ‘mcmc_sample_chain_3/trace_scan/TensorArrayStack_9/TensorArrayGatherV3’:
File “\tensorflow_probability\python\mcmc\”, line 361, in sample_chain
File “\tensorflow_probability\python\mcmc\internal\”, line 372, in trace_scan
stacked_trace = tf.nest.map_structure(lambda x: x.stack(), trace_arrays)
File “\tensorflow_core\python\util\”, line 536, in map_structure
structure[0], [func(*x) for x in entries],
File “\tensorflow_core\python\util\”, line 536, in
Error in (function (…, deparse.level = 1) :
number of rows of matrices must match (see arg 2)

If I run a multivariate normal with sigma to have diagonal elements as one and off diagonals as zero:
multivariate_normal(mu, diag(n_obs))
There is no problem.

Any ideas of what is causing this issue?
I have greta version 0.3.1. and tensorflow version 1.15.


Could you try the code from the webpage instead:, section " Random intercept-slope model (with correlated effects)".

You can also have a look at this conversation: How to use LKJ prior?, for more info on why this parametrization is more efficiently sampled.

No idea what is causing your particular issue though …


Thanks Lionel, I will looks at those.

I was playing with it and I have noticed the same issue when sampling from a multivariate normal distribution in other models. Seems like a TensorFlow issue, but beyond my capabilities to work out.