I need help in interpreting the diagnostics I have printed out from a troublesome run of my model.
As my model includes a large set of user-defined functions, I want to try to explain my problem without including all of the functions block, but if any of you very helpful people need to see it just ask.
On some, but not all, runs of my model I get the (by me) dreaded ‘Log probability evaluates to log(0)’ error.
In my efforts to debug I have inserted some print statements into the model block as shown. You will see that I am using user-defined probability distributions in three of which the parameters are supplied as data, and a fourth where the parameters are found by transforming sampled parameters.
One of the quantities I print is denoted tester
. The log probability is undefined if tester < 0
. When I run the model I supply initial values for the three parameters qtilde1, qtilde2, qtilde3
that are guaranteed to give a positive value for tester
.
data{
// parameters of distribution 1
int<lower = 0> N1;
vector[N1] knots1;
vector[N1] weights1;
// parameters of distribution 1
int<lower = 0> N2;
vector[N2] knots2;
vector[N2] weights2;
// parameters of distribution 1
int<lower = 0> N3;
vector[N3] knots3;
vector[N3] weights3;
int<lower=0> N; // number of observations
vector[N] y; // observations
real u; // high threshold
}
parameters {
real<lower = 0> qtilde1;
real<lower = 0> qtilde2;
real<lower = 0> qtilde3;
}
transformed parameters{
real mu;
real<lower = 0> nu = qtilde3 / qtilde2;
real xi = log10(nu);
real<lower = 0> sigma;
sigma = qtilde2 * xi / (nu * (nu - 1));
mu = qtilde1 - qtilde2 / nu;
}
model {
// priors
qtilde1 ~ weighted_hat_lpdf(knots1, weights1, N1);
print("qt1=",qtilde1);
qtilde2 ~ weighted_hat_lpdf(knots2, weights2, N2);
print("qt2=",qtilde2);
qtilde3 ~ weighted_hat_lpdf(knots3, weights3, N3);
print("qt3=",qtilde3);
print("tester= ", min(1 + xi * (y - mu)/ sigma));
print("lp= ", gpoispoint_lpdf(y | mu, xi, sigma, u))
// log probability
target += gpoispoint_lpdf(y | mu, xi, sigma, u) ;
print("target = ", target());
}
Here is the start of the printed output (the message is repeated 100 times):
Chain 1: qt1=0.878467
qt2=0.703037
qt3=0.497315
tester= 0.622135
lp= -56.6921
target = nan
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: qt1=0.878467
qt2=0.703037
qt3=0.497315
tester= 0.622135
lp= -56.6921
target = nan
The values of qt1, qt2, qt3
are those I supplied. The positive value of tester
shows that they are valid and the printout shows that they do indeed lead to a permissible value for the log probability (lp
).
So why is target = nan
?
I am running this in rstan 2.19.3 on Rstudio 1.2.5033 on a Macbook Pro running Catalina 10.15.5