stan-dev / stan-dev/math

Derive log CDF and log CCDF of transformed distributions from `std_log_lcdf`

Open
#3,364 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Issue #1985 highlighted how changes improving numerical accuracy do not always propagate their benefits to closely related distributions. In the case of standard transformations, the Stan community could capture some DRY benefits from connecting as many derived functions as possible to a reference function that keeps up with the latest numerical improvements (or at least tries to).

While I don't have the overview to make a super-issue of this – there are surely some places where it does make sense to duplicate even lengthy and complicated numerical code – I think there is some low-hanging fruit for the normal distribution. Along the lines of what I tried to do in pull request #3363, I would propose specifically:

  • refactoring normal_lcdf to rely on std_normal_lcdf (with some extra partials lines to avoid autodiffing, as discussed here);
  • refactoring lognormal_lcdf and lognormal_lccdf to rely on normal_lcdf (likewise with some extra partials lines);
  • ditto for exp_mod_normal_lcdf and exp_mod_normal_lccdf; and
  • ditto for skew_normal_lcdf and skew_normal_lccdf.

The wiener5_lpdf function already uses an approach somewhat like this.

On the OpenCL side, there is also std_normal_lcdf_scaled_impl, but I don't understand enough about OpenCL to know whether it would make sense to tie that to std_normal_lcdf also.

If there is agreement that this kind of structure would be useful, I am happy to take a stab at it.

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 the std_normal_lcdf and normal_lcdf entry points, then inspect the lognormal, exp_mod_normal, and skew_normal CDF and CCDF functions named in the issue. Compare their structure with wiener5_lpdf and review the extra partials needed to avoid unnecessary autodiff. Done means the listed functions derive from the reference implementations while preserving their existing behavior and handling the OpenCL question separately.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.