-
-
Notifications
You must be signed in to change notification settings - Fork 198
Closed
Description
Summary:
The cov_matrix parameter type can be inverse transformed from unconstrained space into a result that is not symmetric. Enforce symmetry on it.
Moved from Stan issue stan-dev/stan#1995
Description:
Result should be symmetric. Can take either average of upper and lower triangular or just pick one. Either way, it's critical to ensure the autodiff gives the right result with the copies.
Reproducible Steps:
@andrewgelman reported on stan-users list that the following led to the behavior:
data {
int N;
matrix[N,2] y;
}
parameters {
vector[2] mu;
cov_matrix[2] Sigma;
matrix<lower=-0.5, upper=0.5>[N,2] round_err;
}
transformed parameters {
matrix[N,2] z;
z = y - round_err;
}
model {
for (n in 1:N)
z[n,] ~ multi_normal(mu, Sigma);
}
It was with a dataset with N=185 data points (i.e., y was a 185 x 2 matrix).
If you have a reproducible example, please include it.
Current Output:
Each chain gave a message kinda like this:
The following numerical problems occured the indicated number of times after warmup on chain 4
count
Exception thrown at line 16: multi_normal_log: Covariance matrix is not symmetric. Covariance matrix 14
Exception thrown at line 16: multi_normal_log: LDLT_Factor of covariance parameter is not positive d 2
When a numerical problem occurs, the Hamiltonian proposal gets rejected.
If the number in the 'count' column is small, do not ask about this message on stan-users.
Expected Output:
Symmetry.
Current Version:
v2.11.0