Imroved error message for ~ and non-matching argument type

55 views
Skip to first unread message

Aki Vehtari

unread,
Mar 20, 2015, 4:11:10 PM3/20/15
to stan...@googlegroups.com
I'm already used to this error message, but as I'm now teaching Stan for students, I hope this error message could be improved (a suggestion in the end)

Here's code for Bioassay example written by a student
---
data {
int<lower=0> N;

vector[N] x;
vector[N] y;
int<lower=0> n[N];
}
parameters {
real alpha;
real beta;
}
transformed parameters {
vector[N] mu;
mu <- alpha + beta*x;
}
model {
y ~ binomial_logit(n, mu);
}
---
and compilation gives an error, because y has not been declared as int. But the error message is bit confusing:

---
compile: SYNTAX ERROR, MESSAGE(S) FROM PARSER:
compile: no matches for function name="binomial_logit_log"
compile: arg 0 type=vector
compile: arg 1 type=int[1]
compile: arg 2 type=vector
compile: available function signatures for binomial_logit_log:
compile: 0. binomial_logit_log(int, int, real) : real
compile: 1. binomial_logit_log(int, int, real[1]) : real
compile: 2. binomial_logit_log(int, int, vector) : real
compile: 3. binomial_logit_log(int, int, row vector) : real
compile: 4. binomial_logit_log(int, int[1], real) : real
compile: 5. binomial_logit_log(int, int[1], real[1]) : real
compile: 6. binomial_logit_log(int, int[1], vector) : real
compile: 7. binomial_logit_log(int, int[1], row vector) : real
compile: 8. binomial_logit_log(int[1], int, real) : real
compile: 9. binomial_logit_log(int[1], int, real[1]) : real
compile: 10. binomial_logit_log(int[1], int, vector) : real
compile: 11. binomial_logit_log(int[1], int, row vector) : real
compile: 12. binomial_logit_log(int[1], int[1], real) : real
compile: 13. binomial_logit_log(int[1], int[1], real[1]) : real
compile: 14. binomial_logit_log(int[1], int[1], vector) : real
compile: 15. binomial_logit_log(int[1], int[1], row vector) : real
compile: unknown distribution=binomial_logit
compile: ERROR at line 16
compile: 14: }
compile: 15: model {
compile: 16: y ~ binomial_logit(n, mu);
compile: ^
compile: 17: }
compile: Execute "stanc --help" for more information
---

1) in the second line it mentions
"no matches for function name="binomial_logit_log""
although the code does not have binomial_logit_log (I know why _log, but students don't)
2) if students continue reading past 15 lines of function signatures for
binomial_logit_log, there's a line
"unknown distribution=binomial_logit"
and now students think there's error in the distribution name.

Below is my suggestion for an improved error message

---
compile: SYNTAX ERROR, MESSAGE(S) FROM PARSER:
compile: ERROR at line 16
compile: 14: }
compile: 15: model {
compile: 16: y ~ binomial_logit(n, mu);
compile: ^
compile: 17: }
compile: argument type mismatch for distribution=binomial_logit
compile: arg 0 type=vector
compile: arg 1 type=int[1]
compile: arg 2 type=vector
compile: log-density for distribution=binomial_logit is binomial_logit_log
compile: available function signatures for binomial_logit_log:
compile: 0. binomial_logit_log(int, int, real) : real
compile: 1. binomial_logit_log(int, int, real[1]) : real
compile: 2. binomial_logit_log(int, int, vector) : real
compile: 3. binomial_logit_log(int, int, row vector) : real
compile: 4. binomial_logit_log(int, int[1], real) : real
compile: 5. binomial_logit_log(int, int[1], real[1]) : real
compile: 6. binomial_logit_log(int, int[1], vector) : real
compile: 7. binomial_logit_log(int, int[1], row vector) : real
compile: 8. binomial_logit_log(int[1], int, real) : real
compile: 9. binomial_logit_log(int[1], int, real[1]) : real
compile: 10. binomial_logit_log(int[1], int, vector) : real
compile: 11. binomial_logit_log(int[1], int, row vector) : real
compile: 12. binomial_logit_log(int[1], int[1], real) : real
compile: 13. binomial_logit_log(int[1], int[1], real[1]) : real
compile: 14. binomial_logit_log(int[1], int[1], vector) : real
compile: 15. binomial_logit_log(int[1], int[1], row vector) : real
compile: Execute "stanc --help" for more information
---

Aki

Bob Carpenter

unread,
Mar 20, 2015, 8:49:26 PM3/20/15
to stan...@googlegroups.com
I already simplified it as part of the general parser error
handling. I agree that it's confusing as is, and so does the
users list.

I'm opening a feature request to to try to change
the name to get rid of the _log when used in the sampling context.

https://github.com/stan-dev/stan/issues/1401

See that for more information --- it's also a problem with operator*()
printing errors as "multiply".

I've already gotten rid of the function not found message for
2.6.2 and also changed the output so it looks like the unsized
types in function definitions for consistency (rather than, say real[3]
for a 3-D array it now says real[,,]).

I'll try to get it fixed for our next release. I've been
prioritizing cleaning up error handling.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages