Cannot debug "rejecting initial value" with print?

529 views
Skip to first unread message

Kevin Van Horn

unread,
Mar 7, 2016, 12:57:36 AM3/7/16
to Stan users mailing list
I have a model that isn't even getting started; it fails with a bunch of messages saying "Rejecting initial value: Log probability evaluates to log(0)..." To debug it, I sprinkled print statements all throughout the model block. None of these print statements ever executes. I know that print works -- I put a print statement in the transformed data block, and I see the output. But, apparently, Stan never gets to the model block.

How is Stan concluding that the log prob evaluates to log(0) without ever entering the code that actually computes the log prob?

Krzysztof Sakrejda

unread,
Mar 7, 2016, 1:04:31 AM3/7/16
to Stan users mailing list
That's a great puzzle but without knowing which interface and what Stan program it's hard to guess.

Kevin Van Horn

unread,
Mar 7, 2016, 10:34:27 AM3/7/16
to Stan users mailing list
It's rstan, and it's the same whether I use vb, stan/sampling, or optimizing.

Bob Carpenter

unread,
Mar 7, 2016, 3:20:07 PM3/7/16
to stan-...@googlegroups.com
Start:

log density set to 0

Parameters block:

inverse transform unconstrained params to constrained

increment log density with log Jacobian of inverse transform

Transformed parameter block:

execute block to define parameters

reject if constraints not satisfied

Model block:

executed with ~ and incement_log_prob() incrementing lp

So the only thing I can imagine is that something's going wrong
with the transforms on constrained parameters. But there should
be a better error message than that indicating what's failing.

Which interface are you using?

- Bob

> On Mar 7, 2016, at 12:57 AM, Kevin Van Horn <ke...@ksvanhorn.com> wrote:
>
> I have a model that isn't even getting started; it fails with a bunch of messages saying "Rejecting initial value: Log probability evaluates to log(0)..." To debug it, I sprinkled print statements all throughout the model block. None of these print statements ever executes. I know that print works -- I put a print statement in the transformed data block, and I see the output. But, apparently, Stan never gets to the model block.
>
> How is Stan concluding that the log prob evaluates to log(0) without ever entering the code that actually computes the log prob?
>
>
> --
> You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.
> To post to this group, send email to stan-...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Kevin Van Horn

unread,
Mar 7, 2016, 9:28:37 PM3/7/16
to Stan users mailing list
I'm using rstan. I added a transformed parameter block that contains nothing but a print statement, and that print statement never executes.

Here is the parameters block. I don't see how anything there could be causing trouble.

    parameters {
      real alpha;
      real<lower=0> sigma_noo;
      vector[Nnoo] beta_noo;
      real<lower=0> sigma_sub;
      vector[Nsub] beta_sub;
    
      real<lower=0> sigma_scale;
      vector[Nsub] log_scale;
    
      real<lower=0> sigma_lse;
      real mu_lse;
      vector[Nnoo] log_sigma_err; 

Kevin Van Horn

unread,
Mar 7, 2016, 10:59:26 PM3/7/16
to Stan users mailing list
It appears that it is in fact entering the model block, and at one point in the block an error occurs -- but the *preceding* print statements never output. I'm guessing that an exception is thrown and some buffers are not getting flushed. RAII, anyone?

It seems like I ran into this issue a few years ago, and I thought it had been fixed...


On Monday, March 7, 2016 at 1:20:07 PM UTC-7, Bob Carpenter wrote:

Bob Carpenter

unread,
Mar 8, 2016, 1:02:08 AM3/8/16
to stan-...@googlegroups.com
It does sound familiar. It may have gotten reintroduced
with the refactoring to more general writers in the back end.
Bad on us in that case for not having proper regression tests.

And thanks so much for reporting the issues so well. I
reproduced them easily and moved the RStan issue to Stan --- it's
a more general problem.

- Bob

Charles Driver

unread,
Mar 8, 2016, 8:57:00 AM3/8/16
to Stan users mailing list
I have also been frustrated by print statements not working for the initial likelihood calculation, using rstan in windows... makes troubleshooting difficult. Nice when it gets resolved!

Jonathan Harris

unread,
Jul 5, 2016, 10:05:46 PM7/5/16
to Stan users mailing list
I am having this problem also. Is there a workaround? It is awfully hard to find out why my covvariance matrix is not positive definite if I cannot print intermediate values!

Daniel Lee

unread,
Jul 5, 2016, 10:26:14 PM7/5/16
to stan-users mailing list
Almost -- there's an open pull request to deal with it now:

If you are using CmdStan, you can update the submodule for Stan to the branch there, rebuild CmdStan and your Stan program, and then you'll see print output.


Daniel


Jonathan Harris

unread,
Jul 6, 2016, 6:08:32 AM7/6/16
to Stan users mailing list
Probably won't work. I am trying this on a corporate computer, so I am greatly restricted. I can't even access most Github sites, including the Stan one. 

Michael Betancourt

unread,
Jul 6, 2016, 6:16:58 AM7/6/16
to stan-...@googlegroups.com
There is no workaround without modified the underlying code.  If you can’t
get to the develop branch then you’ll have to wait for the next official release
which won’t be for at least a few months.

Jonathan Harris

unread,
Jul 6, 2016, 6:20:56 AM7/6/16
to Stan users mailing list
What I am trying to do is I have as data the widths of the prior distributions, and am using the transformed data block to stick them into a diagonal matrix. I am using rstan.
i.e.
in data block: 

vector[K] betawd;
in transformed data block:

matrix[K,K] sigbeta;
sigbeta<-diag_matrix(betawd);

in paramters:
vector beta[K];

and in model block:

beta ~ multi_normal(0,sigbeta);

and it says my covariance matrix is not positive definite.

Is there a way I can access or see what I am ending up with in my sigbeta matrix through the stanfit R object or an option in the function call? The print statement won't show anything.

Daniel Lee

unread,
Jul 6, 2016, 6:32:38 AM7/6/16
to stan-...@googlegroups.com
You can start by keeping the print statement and removing the sampling statement.

Or building up to that model. You can replace that line with the normal distribution using the diagonal instead of the matrix. See if that will print anything useful. 



Daniel

Michael Betancourt

unread,
Jul 6, 2016, 6:34:28 AM7/6/16
to stan-...@googlegroups.com
All you can do is replace the multi_normal statement with something
that does not depend on sigbeta and then the print statements will be
output, but you also won’t get the right Markov chain.

But if sigbeta is really diagonal then you don’t need the multi_normal
at all as the multivariate normal decouples into a product of independent
univariate normal distributions.  In that case you can just take advantage
of the vectorization of the univariate normal,

beta ~ normal(0, betawd);

Of course if sigbeta wasn’t positive definite then some of those betawd
are ill-defined and you’ll have have problems.

Bob Carpenter

unread,
Jul 6, 2016, 12:58:07 PM7/6/16
to stan-...@googlegroups.com
It might be as soon as two months. There was a lot
of stuff that got pushed back just past 2.10.

- Bob
Reply all
Reply to author
Forward
0 new messages