how do i test bad log_prob cases?

14 views
Skip to first unread message

Alp Kucukelbir

unread,
Nov 20, 2015, 5:59:48 PM11/20/15
to stan development mailing list
hi stan-dev,

i'm sure one of you has already figured this out.

how do i test bad log_prob situations?

to be specific, i have something like this in my code:

double log_prob = model_.template log_prob<false, true>(zeta, print_stream_);
stan::math::check_finite(function, "log_prob", log_prob);

and i want to make sure that i test for how the rest of my code handles that std::domain_error.

so i need a "bad" model/log_prob :)

many thanks in advance.

cheers
alp

Bob Carpenter

unread,
Nov 20, 2015, 6:03:27 PM11/20/15
to stan...@googlegroups.com
The trick is to use mock objects. You can mock up a model
object that does whatever you want for log_prob.

Or you can go the more roundabout route of writing a Stan
program (again, it can return whatever you want for log density
if there are no constraints --- those bring along Jacobians)
and using that. I can never remember how to do that because it
involves the makefiles.

- 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.

Alp Kucukelbir

unread,
Nov 20, 2015, 6:10:09 PM11/20/15
to stan...@googlegroups.com
could i kindly ask for a pointer to a "good" use of mock objects in a
testing context?

or could someone point me to a stan/data combo where log_prob bombs?

(i don't mind hacking the makefile. i've had to do that many times already.)
> You received this message because you are subscribed to a topic in the Google Groups "stan development mailing list" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-dev/2PSZtiskZFQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to stan-dev+u...@googlegroups.com.

Bob Carpenter

unread,
Nov 20, 2015, 7:58:27 PM11/20/15
to stan...@googlegroups.com
There's an example in

stan/src/test/unit/model/util_test.cpp

You may need more than that implemented for your tests.

- Bob
Reply all
Reply to author
Forward
0 new messages