Skip to content

integrate_1d with normal_density generates wrong integral #2926

Description

@wwguo

Summary:

integrate_1d with normal_density generates wrong integral.

Description:

integrate_1d with the normal_density function provided in stan-users-guide gets wrong integral.

Reproducible Steps:

The normal_density function:

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);
}

Compute following integrals:

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))

Current Output:

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

Expected Output:

integral [N -1.5]: 0.060769
integral [-1.5 P]: 0.939231
integral [N 1.5]: 0.939231
integral [1.5 P]: 0.060769

Current Version:

PyStan 2.19.1.1 and recent CmdStan

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions