I was surprised to find that it is not possible to use the _jacobian and _constrain functions to get bounded vectors that share bounds. This
code <- "
data {}
parameters {vector[2] x_raw;}
transformed parameters {vector[2] x = lower_upper_bound_jacobian(x_raw, -1.0, 1.0);}
model {x ~ std_normal();}
"
cmdstanr::cmdstan_model(cmdstanr::write_stan_file(code))
fails with
Semantic error in '/tmp/Rtmpby1fqc/model-2a279857adbaa1.stan', line 4, column 40 to column 85:
-------------------------------------------------
2: data {}
3: parameters {vector[2] x_raw;}
4: transformed parameters {vector[2] x = lower_upper_bound_constrain(x_raw, -1.0, 1.0);}
^
5: model {x ~ std_normal();}
6:
-------------------------------------------------
Ill-typed arguments supplied to function "lower_upper_bound_constrain":
(vector, real, real)
Available signatures:
(vector, real, vector) => vector
The third argument must be vector but got real
(vector, vector, real) => vector
The second argument must be vector but got real
(vector, vector, vector) => vector
The second argument must be vector but got real
(row_vector, real, row_vector) => row_vector
The first argument must be row_vector but got vector
(row_vector, row_vector, real) => row_vector
The first argument must be row_vector but got vector
(Additional signatures omitted)
make: *** [make/program:66: /tmp/Rtmpby1fqc/model-2a279857adbaa1.hpp] Error 1
Is there a reason that the (vector, real, real) => vector version does not exist? Obviously one can always build the necessary vector but there should be no need.