Log probability evaluates to log(0) error - How to identify which initial value is causing error?

Hi Everyone,

I was trying to debug the log(0) error and some of the Stan forums recommended me to print the output to see which part of the model is causing errors. When I tried printing the values I was getting the output as shown below,

The values printed seem fine. MgCa_calib_m output is the vector that is used as the location parameter in normal distribution. None of it is 0 which can make the output log(0).

Now, how do I identify which initial values are being rejected to debug this error?

Part of Output:
Chain 1: Rejecting initial value:
Chain 1: Log probability evaluates to log(0), i.e. negative infinity.
Chain 1: Stan can’t start sampling from this initial value.
Chain 1: a6: -1.877
Temp: [282.65,280.85,279.15,278.75,278.05,278.05,278.05,277.55,276.05,275.35]
a7: -1.13149
exp_d_mg: [1.86069,1.7402,1.6264,1.59963,1.55277,1.55277,1.55277,1.5193,1.41889,1.37204]
f3: [0.165571,0.290822,0.493274,0.558281,0.693005,0.693005,0.693005,0.80842,1.28101,1.58654]
D_Mg: [0.0352188,0.116576,0.316838,0.393604,0.565849,0.565849,0.565849,0.723891,1.42104,1.88376]
f: [1,1,1,1,1,1,1,1,1,1]
a4: -1.51775
MgCa_calib_m: [-3426.12,-3426.12,-3426.12,-3426.12,-3426.12,-3426.12,-3426.12,-3426.12,-3426.12,-3426.12]
mgca_pre: 0.464185

You want to put a print("target = ", target()) after each target += or ~.

Okay . Thanks. Will do that

So, when I added the line, it did not give me any error on rejecting initial value. But instead the output was like this,

Chain 1: target = -inf
target = -inf
target = -inf
target = -inf
target = -inf
target = -inf
target = -inf

-inf means there is error, right?

The -inf means that the leapfrog step cannot be chosen, but it is not an error. Everything will probably be fine if you set init_r to a value less than 2 when you call stan.

Oh okay. But how do I set init_w to a value less than 2?

stan(..., init_r = 0.5)

Hi @bgoodri,

setting init_r=0.5 worked. But can you explain what is happening when we don’t add init_r vs adding init_r in this case?

I don’t completely understand this

By default, initial values are drawn from a uniform distribution on the unconstrained space between -2 and 2 before being transformed to the space declared in the parameters block of your Stan program. By specifying init_r = 0.5, the initial values are drawn fro a uniform distribution between -0.5 and 0.5.


Thanks for the explanation. This is clear!

So If I add print statement of target after a stochastic variable like this ,

tau~ gamma(3, 17);
print("target = ", target());

In the ouput I can see the values of tau, right?

I would do

print("target = ", target(), " when tau = ", tau);
1 Like

So, if the following lines

tau~ gamma(3, 17);
print("target = ", target());

does not print the values of tau, then what does the target() values represent?

The value of the target keyword which is the logarithm of the kernel of the posterior distribution you are trying to draw from.

1 Like

Okay, Thanks for clearing this confusion!