Open
Description
From @randommm on November 20, 2014 1:55
The following program:
transformed data {
int y[2];
y[1] <- 0;
y[2] <- 1;
print(poisson_ccdf_log(0, 5));
print(poisson_ccdf_log(1, 5));
print(poisson_ccdf_log(y, 5));
}
parameters {
real any;
}
model {
any ~ normal(0, 1);
}
Outputs:
-0.00676075
-0.0412676
-0.0480283
(the last number is the sum of the first two as expected)
However, the following program:
transformed data {
int y[2];
y[1] <- -1;
y[2] <- 1;
print(poisson_ccdf_log(-1, 5));
print(poisson_ccdf_log(1, 5));
print(poisson_ccdf_log(y, 5));
}
parameters {
real any;
}
model {
any ~ normal(0, 1);
}
Outputs:
0
-0.0412676
0
Which doesn't make sense: the last number should have been -0.0412676 too.
The way the CCDFs are currently designed makes them ignore everything when there is a negative random variable inside the vector of random variables:
// Explicit return for extreme values
// The gradients are technically ill-defined, but treated as neg infinity
for (size_t i = 0; i < stan::length(n); i++) {
if (value_of(n_vec[i]) < 0)
return operands_and_partials.to_var(0.0);
}
Copied from original issue: stan-dev/stan#1142