We are very happy to announce that CmdStan 2.37.0 is out!
This release cycle brings improvements to Stan’s constrained types, quality-of-life improvements to CmdStan, and many stability improvements and bug fixes. Thank you to all the developers who contributed to this release!
Starting in this version, there are functions available for each of the built-in transforms. For example, you have long been able to declare a simplex[N] theta;. Now, you can call the functions simplex_jacobian (or simplex_constrain, which does the same transform but does not perform a change of variables adjustment) that takes an unconstrained vector of length N-1 and returns an N-simplex, or simplex_unconstrain which is the inverse operation.
These are useful in some situations where you want to have several constrained variables of different sizes – you can declare one parameter that has the size you need in total, and then constrain slices of that parameter. @mitzimorris used this trick in her case study on the sum to zero vector, but she had to write the sum_to_zero_constrain function herself to do it. Now, Stan gives it to you out of the box
FWIW, I have an example here of the functions to produce multiple simplexes in a matrix. For each group m I need a simplex of size J[m]. So I first produce a vector of probabilities that’s size sum(J - 1).
Then in the transformed parameters I do the following, slicing out of u what I need for each group m:
transformed parameters {
matrix[J_max, M] beta; // matrix of entry probabilities (simplexes)
for (m in 1:M) {
beta[:J[m], m] = simplex_jacobian(u[sum(Jm1[:m - 1]) + 1:sum(Jm1[:m])]);
}
}
Now in the model block I can put a Dirichlet prior on the simplex in the matrix beta. Hope this helps!
EDIT: In my original post I defined the unnormalised probabilities as vector<lower=0, upper=1>[J_sum - M] u, but the lower and upper constraints shouldn’t have been there.
We’ve updated the tarballs associated with this release this morning after we noticed a build machine issue had lead to the wrong version being reported by stanc –version. No code has changed, and there’s no reason explicitly why someone would need to re-download if they already have, I just wanted to note it here in case someone was wondering why the files had changed