Skip to content

Incorrect derivative in bernoulli_logit distributions for some branches #3374

Description

@WardBrian

Reported by @sims1253 for bernoulli_logit_lpmf here and bernoulli_logit_glm_lpmf here.

Here are some tests that would fail if inserted into

TEST_F(AgradRev, mathMixScalFun_bernoulli_logit_glm_lpmf) {

  // internal cutoff for extreme values
  const double cutoff = 20;
  Eigen::MatrixXd x_one(1, 1);
  x_one << 1.0;

  Eigen::Matrix<double, Eigen::Dynamic, 1> beta_one(1, 1);
  beta_one << (cutoff + 5);

  stan::test::ad_tolerances tols;
  tols.gradient_grad_ = 1e-6;

  stan::test::expect_ad(tols, f(0), x_one, 0.0, beta_one);
  stan::test::expect_ad(tols, f(1), x_one, 0.0, beta_one);
  stan::test::expect_ad(tols, f(2), x_one, 0.0, beta_one);

  Eigen::Matrix<double, Eigen::Dynamic, 1> beta_flipped = beta * -1;
  stan::test::expect_ad(tols, f(0), x_one, 0.0, beta_flipped);
  stan::test::expect_ad(tols, f(1), x_one, 0.0, beta_flipped);
  stan::test::expect_ad(tols, f(2), x_one, 0.0, beta_flipped);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions