real normal_density(real x, real xc, real[] theta, real[] x_r, int[] x_i) {
real mu = theta[1];
real sigma = theta[2];
return 1 / (sqrt(2 * pi()) * sigma) * exp(-0.5 * ((x - mu) / sigma)^2);
}
print("integral [N -1.5]: ", integrate_1d(normal_density, negative_infinity(), -1.54835, {0.0, 1.0}, x_r, x_i, 1e-8))
print("integral [-1.5 P]: ", integrate_1d(normal_density, -1.54835, positive_infinity(), {0.0, 1.0}, x_r, x_i, 1e-8))
print("integral [N 1.5]: ", integrate_1d(normal_density, negative_infinity(), 1.54835, {0.0, 1.0}, x_r, x_i, 1e-8))
print("integral [1.5 P]: ", integrate_1d(normal_density, 1.54835, positive_infinity(), {0.0, 1.0}, x_r, x_i, 1e-8))
integral [N -1.5]: 0.939231 // this one is wrong
integral [-1.5 P]: 0.939231
integral [N 1.5]: 0.939231
integral [1.5 P]: 0.060769
integral [N -1.5]: 0.060769
integral [-1.5 P]: 0.939231
integral [N 1.5]: 0.939231
integral [1.5 P]: 0.060769
Summary:
integrate_1dwithnormal_densitygenerates wrong integral.Description:
integrate_1dwith thenormal_densityfunction provided in stan-users-guide gets wrong integral.Reproducible Steps:
The
normal_densityfunction:Compute following integrals:
Current Output:
Expected Output:
Current Version:
PyStan 2.19.1.1 and recent CmdStan