stan-dev / stan-dev/stan

Newton optimizer produces NaN parameters for a target with a flat direction, no error raised

Open
#3,425 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
2.8k
Forks
388
Avg merge
2d 17h
Merged PRs (30d)
15

Description

make_negative_definite_and_solve divides by fabs(eigenvalues[i]) without checking for zeros (division at line 24). For a parameter absent from the target, the Hessian is zero and the step is 0/0:

// model whose log_prob ignores its single parameter, returns 0.5
stan::optimization::newton_step<flat_model, false>(model, params_r, params_i);
// f0 = 0.5, params_r[0] = -nan

The caller loop accepts NaN (while (f1 < f0) is false for NaN) and the service returns error_codes::OK without a finiteness check, so the run reports success with NaN parameters. Probably related to #3306.

Environment:
  • Ubuntu 22.04.5 LTS (WSL2, kernel 6.18.33.2-microsoft-standard-WSL2), x86_64
  • stan-dev/stan develop @ 8ad5c989c (stan::math develop @ d20b238b9c)
  • g++ 11.4.0 (Ubuntu 22.04), -std=c++17

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with make_negative_definite_and_solve in src/stan/optimization/newton.hpp and trace the caller loop and return path in src/stan/services/optimize/newton.hpp. Reproduce the flat_model case described in the issue, then inspect how the optimizer handles zero Hessian eigenvalues and non-finite parameters. Done means the flat-direction run no longer reports success with NaN parameters and has coverage for the failure or safe result.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.