Binomial_lpmf(x | x, 1.0) returns nan

Hello stanimaniacs,

When I’m trying to implement binomial mixture model, I noticed binomial_lpmf(x | y, 1.0) function with probability=1.0 returns nan or -Inf. By this effect, my model failed to initialize.
In my mind, it should return 0 when x is equal to y.
What is the reason of the behavior?

Here is stan code of the behavior

model {
    print("binomial_lpmf(10|10, 1.0)=", binomial_lpmf(10 | 10, 1.0)) ;
    print("binomial_lpmf(5|10, 1.0)=", binomial_lpmf(5 | 10, 1.0)) ;
    print("binomial_lpmf(10|5, 1.0)=", binomial_lpmf(10 | 5, 1.0)) ;
    target += binomial_lpmf(10 | 10, 1.0) ;
}

Python code

from pystan import StanModel

fit = StanModel("bmm.stan")
fit.optimize()

And the stdout

binomial_lpmf(10|10, 1.0)=nan
binomial_lpmf(5|10, 1.0)=-inf
binomial_lpmf(10|5, 1.0)=
Rejecting initial value:
  Error evaluating the log probability at the initial value.
Exception: binomial_lpmf: Successes variable is 10, but must be in the interval [0, 5]  (in 'mbm.stan' at line 4)


Initialization between (-2, 2) failed after 1 attempts.
 Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/MYNAME/.pyenv/versions/3.6.2_stantest/lib/python3.6/site-packages/pystan/model.py", line 550, in optimizing
    ret, sample = fit._call_sampler(stan_args)
  File "stanfit4anon_model_24b72157deefeceb46afa569a0b2c4f8_5860909900324935073.pyx", line 997, in stanfit4anon_model_24b72157deefeceb46afa569a0b2c4f8_5860909900324935073.StanFit4Model._call_sampler
  File "stanfit4anon_model_24b72157deefeceb46afa569a0b2c4f8_5860909900324935073.pyx", line 404, in stanfit4anon_model_24b72157deefeceb46afa569a0b2c4f8_5860909900324935073._call_sampler
RuntimeError: Initialization failed.

Software versions

  • pystan: 2.19.0.0( and this also reproduced by 2.17.1.0)
  • python: 3.6.2 with pyenv