Getting random variables in my logp function while using pymc_extras.statespace

Yes, Stan lets yo declare parameters to be positive definite and we have an inverse Wishart distribution. For efficiency and numerical stability, we recommend parameterizing directly with Cholesky factors as follows.

data {
  cholesky_factor[10] L_S;
  real<lower=0> nu;
}
parameters {
  // ensures L_Sigma lower triangular w. strictly positive diagonal
  cholesky_factor[10] L_Sigma;  
}
model {
  L_Sigma ~ inv_Wishart_cholesky(nu, L_S);
}

For inspection or output, you can recover the latent positive definite matrix Sigma as follows.

generated quantities {
  cov_matrix[10] Sigma = L_Sigma * L_Sigma';
}

For details on the transforms and Jacobian adjustments, see:

2 Likes