Skip to content

Derive log CDF and log CCDF of transformed distributions from std_log_lcdf #3364

Description

@jaburgoyne

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions