stan-dev / stan-dev/stan

add poisson_log_lcdf and poisson_log_lccdf functions

Open
#2,015 22 comments 0 reactions 2 assignees View on GitHub

@bob-carpenter is already working on this.

Since Aug 17, 2016.

good first issue new function
Dominant language
C++
Stars
2.8k
Forks
388
Avg merge
2d 17h
Merged PRs (30d)
15

Description

Summary:

[From @bob-carpenter: I edited the title to highlight the root cause. You can skip all the discussion; just missing the underlying functions at this point.]

I'm fitting a model with the poisson_log function (i.e. a Poisson distribution parameterized by log(lambda) instead of lambda).

I'm running into two problems:

  • Large number of divergent transitions with a simple model (well over 50% of the post-warmup iterations)
  • If I add truncation, I start getting errors about negative lambda values and my log(rate) parameter is squashed up against 0.

My best guess is that truncation flips a switch somewhere that leads to stan::math::poisson_log_log when it should go to to stan::math::poisson_log. I can't explain the divergent transitions, but I think it also might be related. Maybe an incorrect nonlinear transform?

Reproducible Steps:
compiled = stan_model(model_code =
"data {
  int<lower=1> N;
  int<lower=1> y[N];
}
parameters {
  real log_rate;
}
model {
  log_rate ~ normal(0.0, 1.0);
  for(i in 1:N){
    y[i] ~ poisson_log(log_rate) T[1, ];
  }
}
"
)

y = rpois(1000, 1)
y = y[y>0]
data = list(y = y, N = length(y))

m = sampling(compiled, data = data)

As noted above, the non-truncated version (i.e. the above code with T[1, ] removed on line 12) also has problems.

Current Output:

Sampling without truncation:

  • There were 2768 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help.
  • samples of log_rate approximately Gaussian and can span 0, depending on the distribution of y in data.

Sampling with truncation:

  • If the model initializes, I get many iterations of Exception thrown at line 12: poisson_log: Rate parameter is -2.24632e-13, but must be >= 0! 1
  • With an earlier (more complicated) version of the model that didn't initialize, I instead got [596] "Exception thrown at line 12: stan::math::poisson_log: Rate parameter is -0.989166, but must be >= 0!" Note the reference to stan::math::poisson_log instead of stan::math::poisson_log_log
  • There were 1065 divergent transitions after warmup. Increasing adapt_delta above 0.8 may help
Expected Output:

MCMC samples

Current Version:

rstan 2.11.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.