Repository navigation
Conversation
Jenkins Console Log Machine informationDistributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 43 bits physical, 48 bits virtual CPU(s): 256 On-line CPU(s) list: 0-255 Thread(s) per core: 2 Core(s) per socket: 64 Socket(s): 2 NUMA node(s): 2 Vendor ID: AuthenticAMD CPU family: 23 Model: 49 Model name: AMD EPYC 7742 64-Core Processor Stepping: 0 Frequency boost: enabled CPU MHz: 1497.237 CPU max MHz: 3416.0681 CPU min MHz: 1500.0000 BogoMIPS: 4491.85 Virtualization: AMD-V L1d cache: 4 MiB L1i cache: 4 MiB L2 cache: 64 MiB L3 cache: 512 MiB NUMA node0 CPU(s): 0-63,128-191 NUMA node1 CPU(s): 64-127,192-255 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Old microcode: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Mitigation; untrained return thunk; SMT enabled with STIBP protection Vulnerability Spec rstack overflow: Mitigation; Safe RET Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Retpolines; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsa: Not affected Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Mitigation; IBPB before exit to userspace Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es G++: g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Clang: clang version 10.0.0-4ubuntu1 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin |
|
@avehtari Hi! I was working on something related and took a similar, but a bit different approach. Here are some notes on how this can be further improved. I have this on a branch with Hessian tests (η from −800 to 720) and the Laplace test. I can fold it into this PR or rebase it as a follow-up once this is merged, or you can paste these to your agent. lmk what is a preferred option. :) CommentsChecked at 468ff26 with a probe (
Rows 1 and 6 are regressions of this branch (inf/inf; All of it goes away by never forming where log(1+e^u) is your |
|
@jachymb thanks for the review and suggestions. I'll check these |
…oose without rounding phi
|
@jachymb Rows 1 and 6 are regressions of this PR, and I could reproduce them. Your formulas are correct, and I used them. In the other PR checking your comments lead to additional findings, so I did ask Claude to check your comments, too, but I guess here the fix is the same as you had. Below there is one request for you
Row 7, the I also saw #3446 for the |
|
@avehtari could you resolve the conflicts in this PR to let jenkins run? |
|
conflict resolved (it was only in the include block) |
Jenkins Console Log Machine informationDistributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 52 bits physical, 57 bits virtual CPU(s): 192 On-line CPU(s) list: 0-191 Thread(s) per core: 2 Core(s) per socket: 48 Socket(s): 2 NUMA node(s): 2 Vendor ID: AuthenticAMD CPU family: 25 Model: 17 Model name: AMD EPYC 9474F 48-Core Processor Stepping: 1 Frequency boost: enabled CPU MHz: 1497.526 CPU max MHz: 4114.4229 CPU min MHz: 1500.0000 BogoMIPS: 7189.39 Virtualization: AMD-V L1d cache: 3 MiB L1i cache: 3 MiB L2 cache: 96 MiB L3 cache: 512 MiB NUMA node0 CPU(s): 0-47,96-143 NUMA node1 CPU(s): 48-95,144-191 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Old microcode: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Mitigation; Safe RET Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsa: Mitigation; Clear CPU buffers Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Mitigation; IBPB before exit to userspace Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d debug_swap G++: g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Clang: clang version 10.0.0-4ubuntu1 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin |
|
Action: Not Ready for Human Review Commit checked: SummaryThank you for this PR and for the mpmath reference values in the tests. The PR says that differences of lgamma, lbeta and digamma at large shape parameters lose all digits on develop in 24 functions, and that two new helpers, digamma_diff and log_beta_ratio, repair the values and gradients. I read the source and test changes at c962588. The output of each run is in this gist.
Claims and EvidenceEach section below lists facts from the PR summary and discussion that an agent was able to confirm, partially confirm, or not confirm at all, or that a run of the code in the PR contradicted. Confirmed FactsFACT: The three points of #2508 are wrong on develop by 5.3e-8, 2.8e-4 and 693, and the PR fixes themQuote:
STATUS: ConfirmedThe three points are rows 4 to 6 of Evidence:The test rows are in the PR, with reference values that agree with the binomial limit -3.67992 given in #2508. What I ran: FACT: digamma_diff(x, 1) equals 1 / x exactly from x = 1e-300 to 1e300Quote:
STATUS: Confirmed
Evidence:The test is in the PR. What I read: digamma_diff.hpp L118-L125 sends an arithmetic d = 1 through the count path, which returns What I ran: FACT: lkj_corr_lpdf dropped d/deta at eta == 1, where develop returns -0.165 and the exact value is 1.2214Quote:
STATUS: Confirmed
Evidence:The test is in the PR. What I read: lkj_corr_lpdf.hpp L53-L61 computes the eta partial with digamma_diff after the eta == 1 branch, so both branches get it. What I ran: FACT: OpenCL neg_binomial_2_log_glm_lpmf with a scalar alpha and a vector phi failed on developQuote:
STATUS: Confirmed
Evidence:The test opencl_matches_cpu_mixed_alpha_phi is in the PR. What I read: On develop the prim function set What I ran: FACT: At small phi the partials were already correct on developQuote:
STATUS: ConfirmedOn develop with large_shapes_test.cpp copied in, the rows at phi = 1e-8 and 1e-17 of neg_binomial_lpmf, neg_binomial_2_lpmf and neg_binomial_2_log_lpmf fail only in the value. Evidence:The test rows are in the PR. What I ran: FACT: The GLM theta partial is NaN at theta = 720 and -inf at theta = 709 on develop, and the exact value is -1.5Quote:
STATUS: ConfirmedThe two theta rows of large_shapes_test.cpp check the alpha and beta partials, which both equal the theta partial at x = 1, against -1.5 to 1e-11. Evidence:The test rows are in the PR. What I ran: FACT: A new test checks full - propto against the dropped termsQuote:
STATUS: Confirmed
Evidence:The test is in the PR. What I ran: FACT: With develop's headers, the new beta_binomial and large-shape cases fail, and the old cases and the propto case passQuote:
STATUS: ConfirmedOn develop with the PR's test files copied in, which uses all of develop's headers, the 4 new beta_binomial cases fail (large_shapes, binomial_limit, log_shape_gradients and log_concentration_gradient). Evidence:The tests are in the PR. What I ran: FACT: At the current head, the negative binomial unit tests, the generated test/prob tests (23 490 cases) and the four OpenCL negative binomial suites passQuote:
STATUS: ConfirmedThe PR does not list its 25 files, so I chose the 25 files of the negative binomial family by name. Evidence:The test files are in the repository and the PR. What I ran: Partially Confirmed FactsFACT: In the model of #3153, develop's value and lc gradient are wrong, and the PR is within 2.3e-14 and 3.7e-14 for lc from 0 to 44Quote:
STATUS: Partially ConfirmedThe tests check this model at some of the points. On develop with these tests copied in, they fail. The bounds 2.3e-14 and 3.7e-14 over lc from 0 to 44, the row at lc = 28, and the other exact entries come from a sweep that is not in the PR. Evidence:The tests have the points above, with mpmath reference values. What I ran: Request: Could you add or link the script behind the table and the bounds 2.3e-14 and 3.7e-14 for lc from 0 to 44 (the mpmath reference and the Stan Math driver)? FACT: Fixes #1578: the error of alpha * d/dalpha of neg_binomial_lpmf reaches 3.0 on develop at alpha = 1e15 and is 1e-14 with this PRQuote:
STATUS: Partially ConfirmedThe The example in #1578 (n = 0, alpha = 1e10 + 1, beta = 0.8, where d/dalpha is about -0.81093 and d/dbeta about 6.94e9) is not a test row. Evidence:The large-shape rows are in the PR. What I read: At d12f488, neg_binomial_lpmf.hpp L26 defines What I ran: Request: Could you add the example from #1578 as a test row? FACT: The table of worst errors at large shapes, on develop and with this PRQuote:
STATUS: Partially ConfirmedThe rows of large_shapes_test.cpp and the beta_binomial tests are at these shapes.
At the head every row passes, to 1e-12 relative in the value and 1e-11 in the gradient (1e-6 and 1e-4 for the beta_binomial and beta_neg_binomial cdfs). Evidence:The test rows, with mpmath reference values, are in the PR. What I ran: Request: Could you add or link the script that measured the worst errors in this table, for develop and for this PR? FACT: On develop, beta_binomial_lcdf returned NaN at 16 of 81 test points and was wrong by up to 61Quote:
STATUS: Partially ConfirmedThe Evidence:Four test rows. What I ran: Request: Could you add the 81 points, or the script that checks them? FACT: OpenCL beta_binomial_lpmf did not check 0 <= n <= N, and returned -8.216 under propto for n = 6, N = 5Quote:
STATUS: Partially ConfirmedThe code part follows from reading. The red run cannot show the values on develop. Evidence:The test opencl_n_outside_support is in the PR. What I read: On develop the kernel results do not include What I ran: Request: Could you put the defect-3 test where it compiles against develop, for example in its own file or with the scalar-shape reference rows in a separate test file? FACT: The negative binomial functions lost phi at small phi on develop, and the PR's errors at these points are at most 5.3e-13Quote:
STATUS: Partially ConfirmedThe rows marked small phi and small alpha in large_shapes_test.cpp check these points for neg_binomial_lpmf, neg_binomial_2_lpmf, neg_binomial_2_log_lpmf and the GLM, to 1e-12 relative. The test tolerance is 2.5e-11 to 3.9e-11 at these values, so the tests do not show the bound of 5.3e-13. Evidence:The test rows are in the PR. What I read: The What I ran: Request: Could you add the script behind the bound of 5.3e-13, or tighten the tolerance of these rows to that bound? FACT: neg_binomial_2_lpmf evaluates log(mu + phi) once when phi is autodiff, and the results are bitwise identicalQuote:
STATUS: Partially ConfirmedThe first part follows from the code. Evidence:The code change is in commit 1c8afb7. What I read: neg_binomial_2_lpmf.hpp L63-L65 stores the log, and L72 and L94 read it. Request: Could you add or link the check that compared the results bit for bit, for example a test that runs both forms on the same inputs? FACT: With develop's OpenCL files, every new absolute-reference test and the two tests of defects 3 and 4 fail, and the old differential tests pass except opencl_matches_cpu_big of the GLMQuote:
STATUS: Partially ConfirmedMy base tree is all of develop at d12f488 with the PR's tests copied in, which differs from your swap of the develop OpenCL files into the branch.
At the head all tests in the six files pass. Evidence:The six OpenCL test files are in the PR. What I ran: Request: Could you say which files your swap replaced, or give a version of the beta_binomial OpenCL tests that compiles against develop? FACT: beta_binomial_lcdf(3 | 10, 298.3, 146.75) is NaN, with exact value -3.93335, for a different causeQuote:
STATUS: Partially ConfirmedThe stated mechanism follows from the code of hypergeometric_3F2 at the head. Evidence:The PR does not include test at this point. What I read: hypergeometric_3F2.hpp L45-L50 replaces zero parameters by 1, so Request: Could you add this point as a test that records the current result, or link the test in #3437 that covers it? Not Verified FactsFACT: The references are mpmath at 80 to 140 digits, and two independent routes agreeQuote:
STATUS: Not VerifiedComments in the test files say that the reference values come from mpmath, but the PR does not include the mpmath scripts or the second route. Evidence:Comments in the tests. Request: Could you add the mpmath scripts that produce the reference values in the tests, with both routes, or link them in a gist? FACT: Over 7 281 points the error of digamma_diff is at most 4.2 ulpQuote:
STATUS: Not VerifiedThe prim test checks 17 mpmath values to 1e-15 relative, about 4.5 ulp, and passes at the head (cpu_tests-head.out). Evidence:17 test values. Request: Could you add or link the sweep script, with the reference values? FACT: The student_t series has errors of at most 0.9 and 2.4 eps from h = 20 to 1e15Quote:
STATUS: Not VerifiedThe Evidence:Four test points. Request: Could you add or link the script that compares the series with mpmath over this range? FACT: Without the selection in log_beta_ratio, points with N = 1e6 and one small shape lost up to 4e-11Quote:
STATUS: Not VerifiedThe rev beta_binomial test has rows with N = 1e6 and one small shape, and they pass at the head to 1e-13 relative in the value (cpu_tests-head.out). Evidence:The rows with the selection are in the PR. Request: Could you add or link the comparison that shows the loss of 4e-11 without the selection? FACT: The fvar Hessian entry of the GLM in theta is now -4.7225e-17 at theta = 35 and -1.40777e-13 at theta = 27Quote:
STATUS: Not VerifiedThe PR does not include a test or a script for the second derivatives. Evidence:The PR does not include code for these numbers. Request: Could you add a test of these two Hessian entries, or link the probe that computed them? FACT: student_t_lpdf runs 2.4 % more instructions for nu < 40, 52 % fewer for nu >= 100, and the scalar value takes 0.35 times as longQuote:
STATUS: Not VerifiedThe PR does not include the benchmark or the instruction counts behind these numbers. Evidence:The PR does not include benchmark. Request: Could you add or link the benchmark, for example a google-benchmark file and the command that counted instructions? FACT: Time ratios to develop for the other changed functionsQuote:
STATUS: Not VerifiedThe PR does not include the benchmark that produced the table. Evidence:The PR does not include benchmark. Request: Could you add or link the benchmark source and the script that interleaves the rounds? FACT: A probe of the 14 changed densities matches the propto and full values of develop at all 456 pointsQuote:
STATUS: Not VerifiedThe probe is not in the PR. Evidence:The probe is not in the PR. Request: Could you add or link the probe? FACT: For the GLM with data phi, the propto value has a rounding error of about eps * phi log(phi)Quote:
STATUS: Not VerifiedThe PR does not include a test or a script that shows the size of this error. Evidence:The PR does not include code for this statement. Request: Could you add a short test or script that shows the size of this error at a large phi? FACT: beta_neg_binomial_cdf now returns 0 with NaN gradients at 15 of 2352 points where develop returns finite valuesQuote:
STATUS: Not VerifiedThe PR does not include the grid of 2 352 points or a test at one of the 15 points, so this change from develop cannot be rerun. Evidence:The PR does not include code for this statement. Request: Could you add one of the 15 points as a test, or link the grid script? Contradicted FactsFACT: On develop, the worst error of multi_student_t and yule_simon_lpmf at large shapes is about 2e-7Quote:
STATUS: ContradictedThe PR's own rows show larger errors on develop. Evidence:The rows What I ran: Request: Could you check the develop column of these two rows? Description vs CodeEach section below lists facts from the PR summary and discussion that an agent was able to confirm, partially confirm, or not confirm at all, or that a run of the code in the PR contradicted. Confirmed FactsFACT: digamma_diff has three paths: a count from 0 to 8, the plain difference for x < 10 and d >= 10, and a shift with an asymptotic series otherwiseQuote:
STATUS: Confirmeddigamma_diff.hpp L118-L126 sums 1 / (x + j) from the smallest term when FACT: digamma_diff is public, not in the Stan language, and used by 19 distribution files and the derivatives of lbetaQuote:
STATUS: Confirmeddigamma_diff is in FACT: digamma_diff is vectorized, works with the autodiff types, and has an OpenCL device function and a kernel-generator registrationQuote:
STATUS: Confirmeddigamma_diff.hpp L186-L194 vectorizes it with apply_scalar_binary, and the scalar version uses generic arithmetic on FACT: log_beta_ratio selects the Stirling form or the plain lbeta form by the size of their termsQuote:
STATUS: Confirmedlog_rising_factorial_ratio.hpp L202-L239 uses the Stirling form when both shapes are large and FACT: The lbeta partial in an argument of at least 10 is -digamma_diff, and below 10 it is the plain differenceQuote:
STATUS: ConfirmedIn rev/fun/lbeta.hpp L21-L45, FACT: The GLM evaluates the terms that depend on y only once per distinct count, if the largest count is at most 4 N + 64, in the CPU version onlyQuote:
STATUS: Confirmedneg_binomial_2_log_glm_lpmf.hpp L211-L222 turns on the table for a vector y and a scalar phi when the largest count is at most FACT: student_t_lpdf is unchanged for nu < 40 and uses the stated series from nu = 40Quote:
STATUS: Confirmedstudent_t_lpdf.hpp L38-L101 uses the lgamma and digamma differences below 40 and the series with the coefficients in the description from 40 on. FACT: Each term of the lkj constant is lgamma(k/2) - lbeta(k/2, x), and the eta partial is set with digamma_diffQuote:
STATUS: Confirmedlkj_corr_lpdf.hpp L44-L62 adds FACT: The changes per function for beta_binomial, beta_neg_binomial, neg_binomial, dirichlet_multinomial, yule_simon and multi_student_tQuote:
STATUS: ConfirmedThe code at the head matches each listed change, for example beta_binomial_lpmf.hpp L118-L141 (log_beta_ratio and digamma_diff), neg_binomial_lpmf.hpp L80-L105 ( FACT: beta_binomial_lcdf uses the mirror relation where C > 1/2, except for alpha = 1Quote:
STATUS: Confirmedbeta_binomial_lcdf.hpp L118-L150 takes the mirrored series with the shapes swapped when FACT: The OpenCL versions of six functions compute the same formulas as the CPUQuote:
STATUS: ConfirmedThe OpenCL prim files of beta_binomial_lpmf, neg_binomial_lpmf, neg_binomial_2_lpmf and neg_binomial_2_log_lpmf use FACT: The code adds back the constants that propto drops in yule_simon_lpmf and the GLM, also in OpenCLQuote:
STATUS: Confirmedyule_simon_lpmf.hpp L71-L74 subtracts lgamma(n) under propto. Partially Confirmed FactsFACT: large_shapes_test.cpp has 92 rows, with points where develop was wrong plus one small-shape point per functionQuote:
STATUS: Partially ConfirmedThe file has 92 rows. Request: Could you update the sentence to say that the GLM rows at small phi check a regression of an earlier commit? Contradicted FactsFACT: Each of the other 26 distribution files adds 3 to 61 linesQuote:
STATUS: Contradicted
Request: Could you add prim/prob/neg_binomial_2_log_glm_lpmf.hpp (154 added lines) to the table and update the range for the other files? Not Checked
|
|
Reply to @stevieb-bot. I merged develop into the branch and added and moved tests. I put the scripts behind the numbers in a public repository, measured every number of the description again, and replaced the description. In this reply, "develop" is the new merge base ScriptsThe scripts are in stan-pr-checks/pr3434. The README has one section per claim, with the commands, the expected output and the commits. The directory has:
I ran all accuracy scripts again on develop and on the PR ( Numbers that changed in the rerun
Partially confirmed and not verified facts
Contradicted fact
Description vs code
Other changes
|
EDIT: 2026-10-29 updated after revision
Fixes #3153. Fixes #1578. Addresses #2508 partially.
This PR improves
beta_binomial_lpmf,beta_binomial_cdf,beta_binomial_lcdf,beta_binomial_lccdf,beta_neg_binomial_lpmf,beta_neg_binomial_cdf,beta_neg_binomial_lcdf,beta_neg_binomial_lccdf,neg_binomial_lpmf,neg_binomial_2_lpmf,neg_binomial_2_log_lpmf,neg_binomial_2_log_glm_lpmf,dirichlet_multinomial_lpmf,lkj_corr_lpdf,lkj_corr_cholesky_lpdf,lkj_cov_lpdf,student_t_lpdf,multi_student_t_lpdf,multi_student_t_cholesky_lpdf,yule_simon_lpmf,yule_simon_cdf,yule_simon_lcdf,yule_simon_lccdf, and the derivatives oflbeta.Claude assisted with this PR.
The scripts behind the numbers in this text are in stan-pr-checks/pr3434. Its README has one section per claim, with the commands, the expected output and the commits. "Develop" in this text is the merge base
510d263078.Summary
Several distributions form a difference
f(x + k) - f(x). Herefislgamma,lbetaordigamma,xis a shape, concentration, dispersion or degrees-of-freedom parameter, andkis a count or an offset. Whenxis large, the two terms are large and almost equal, and the difference keeps no correct digits. In the values the terms have the size ofx, so the error is abouteps * x. In the gradients the terms are aboutlog(x), and a model with the parameter on the log scale multiplies the error byx.In the model of #3153,
beta_binomial_lpmf(57 | 117, s, s)withs = exp(lc) / 2, develop returns a log probability 81 too high fromlc = 42. Its gradient inlcis 0 or noise fromlc = 24, so warmup stops in a region where the log density is flat. With this PR, forlcfrom 0 to 44 in steps of 0.25, the value is within4.3e-14of the exact value. The gradient is within3.7e-14.lcd/dlcFrom
lc = 34, the exact values are below the rounding error of any form (about2e-14), because57 log p + 60 log qis about -81 there.#2508 reports the same defect:
beta_binomial_lpmf(500 | 1000, s, s)fors = 0.5e10, 0.5e13, 0.5e19. Develop is wrong by5.3e-8,2.8e-4and693there, and returns+689.47at the largests. This PR fixes all three points, and they are rows ofprim/prob/beta_binomial_test.cpp. This PR does not close #2508. The comment there aboutbeta_binomial_lcdf(3 | 10, 298.3, 146.75)(NaN, exact-3.93335) has a different cause.hypergeometric_3F2does not stop at the zero term of the terminating series3F2({1, 302.3, -6}; {5, -151.75}; 1)(exact17.63), and a later0 * infgivesNaN. #3437 repairs that and closes #2508; its test has this point.#1578 reports wrong derivatives of
neg_binomial_lpmffor largealpha. Its example (n = 0,alpha = 1e10 + 1,beta = 0.8) is already correct on develop, because develop no longer uses the Poisson approximation that the issue describes. The example is now a row oflarge_shapes_test.cpp, and it passes on develop too. This PR repairs the cancellation that remains ind/dalpha = digamma(alpha + n) - digamma(alpha) + log(beta / (1 + beta)). The cancellation matters when the meanalpha / betastays fixed. There, the error ofalpha * d/dalphaon develop reaches 3.0 atalpha = 1e15. With this PR it is at most1.0e-14over 42 points with the mean fixed at 3 or 50.The same root cause is in more functions. The table gives the worst absolute error over a sweep of each function. Where the value or the gradient is large, it also gives the relative error at that point. For shape-type arguments, "gradient" is the log-shape gradient
x * d/dx, the gradient that a sampler sees when the model parameter islog(x).beta_binomial_lpmf(shapes up to 1e18)beta_neg_binomial_lpmfneg_binomial_lpmf,neg_binomial_2_lpmf,neg_binomial_2_log_lpmfneg_binomial_2_log_glm_lpmfdirichlet_multinomial_lpmflkj_corr_lpdf,lkj_corr_cholesky_lpdfyule_simon_lccdfyule_simon_cdf,yule_simon_lcdfbeta_binomial_{cdf,lcdf,lccdf}NaNbeta_neg_binomial_{cdf,lccdf}beta_neg_binomial_lcdfstudent_t_lpdfnugradient 0.14multi_student_t_lpdf,multi_student_t_cholesky_lpdfnugradient 8.9e-5yule_simon_lpmflbeta(var,fvar), derivativeThe parameters go up to 1e15, with these exceptions. The
beta_binomial_lpmfsweep goes up to 1e18, because the model of #3153 reaches 8.7e17 atlc = 42. Up to 1e15, the develop errors of this row are 0.19 and 7.6. Thestudent_t_lpdfandlbetarows go up to 1e14. Themulti_student_tandyule_simon_lpmfrows go up to 1e12, with counts up to 1e6. For the lpmf and lpdf rows, where the PR column has an absolute error above 1e-12, the value or the gradient is of order 1e5 to 1e15. There the relative error is at the rounding level.yule_simon_cdfand_lcdfare1 - candlog1p(-c)with a tinyc = n B(n, alpha + 1), so their errors show only in relative terms. That row comes from 24 points per function withalphaup to 1e15 andnup to 20 (review_rows/). The cdfs ofbeta_binomialandbeta_neg_binomialkeep the tolerance of their 3F2 series.All references come from two independent mpmath routes that agree. The values use
loggamma, the gradients closed-formdigammadifferences andmp.diff, and the cdfs sums of the pmf. The references are at 80 to 140 digits; those ofstudent_t_lpdf,multi_student_t,yule_simon_lpmfandlbetaare at 50 digits, checked at 110. At the sweep points of the table, no PR error is above 4 times the develop error. The exceptions are at the rounding level of the point or within the series tolerance of a cdf. At these points the PR has no moreNaNvalues or throws than develop (beta_binomial_lcdf: 16NaNon develop, 0 with this PR). For thebeta_neg_binomial_cdfgrid, see "Limits that remain".neg_binomial_lpmf,neg_binomial_2_lpmfandneg_binomial_2_log_lpmfalso lost the digits ofphiat smallphi, and the GLM partials overflowed at largetheta. This PR repairs both (items 5 and 6 of "Related defects fixed in this PR").propto. In some of the new forms, a constant thatproptodrops cancels against terms that depend on a parameter. The code cannot skip such a constant. For example,lbeta(n, alpha + 1)containslgamma(n). To keep theproptobehavior, the code subtracts such a constant from the result whenproptodrops it. Inyule_simon_lpmfthis islgamma(n). Inneg_binomial_2_log_glm_lpmfit islgamma(y + 1),phi log(phi)(dataphi) andy theta(datax,alphaandbeta), also in OpenCL. For the GLM with dataphi, this adds a rounding error of abouteps * phi log(phi)to theproptovalue. In a probe with five observations, the error atphi = 1e12is 5.2e-3, againsteps |propto value| = 3.1e-2; develop's error has the same size. A probe of all 14 changed densities uses every combination of data and parameter arguments. It matches theproptoand full values of develop in all 456 values. A new test checksfull - proptoagainst the dropped terms.Most of the added source lines are in these files:
prim/fun/log_rising_factorial_ratio.hpp(new helpers)prim/fun/digamma_diff.hpp(new)opencl/kernels/device_functions/log_beta_ratio.hpp(new)prim/prob/neg_binomial_2_log_glm_lpmf.hppopencl/kernels/device_functions/digamma_diff.hpp(new)opencl/kernel_generator/elt_function_cl.hpp(registrations)student_t_lpdf(series), CPU and OpenCLThe other 25 distribution files (CPU, OpenCL and the GLM kernel) add 3 to 56 lines each. The
revandfwdlbetafiles add 28 and 27.What this PR adds
digamma_diff(x, d) = digamma(x + d) - digamma(x), a new function inprim/fun. It is public, but not exposed in the Stan language, because 19 distribution files and the derivatives oflbetause it.log_rising_factorialcan use it in a follow-up. It has three paths:dfrom 0 to 8 (a count):sum_{j < d} 1 / (x + j). All terms are positive, andd = 1gives exactly1 / x;x < 10andd >= 10: the plain difference, which loses only a few ulp there (the result is at least 0.72 anddigamma(x) <= 2.25);log1p(d / y)plus the asymptotic series, with the differencesy^-2i - (y + d)^-2iformed as(u - v) h_iso that nothing cancels.Over 7 281 points,
xfrom1e-3to1e18anddfrom1e-6to1e7, the error is at most 4.2 ulp; the plain difference reaches6.5e16ulp. The function is vectorized and works with all autodiff types through generic arithmetic, withexpect_adtests. The PR also adds an OpenCL device function with the same paths and a kernel-generator registration.internal::log_rising_factorial_ratio,internal::log_beta_ratioand their helpers inprim/fun/log_rising_factorial_ratio.hpp. They write eachlgammathroughlgamma_stirling_diff, so that the terms linear in the arguments cancel exactly. They form the rest without cancellation: they split off thex log1p(k / x) - kparts fork < xand add the integer parts exactly.log_beta_ratio(alpha, beta, n, m) = lbeta(alpha + n, beta + m) - lbeta(alpha, beta)selects the Stirling form or the plainlbetaform by the size of their terms. The Stirling form has rounding errors of the size ofn + m, and thelbetaform of the size of the smaller shape. With the Stirling form at all points, the error rose to6.1e-11relative (2.8e-10absolute) at 131 of the 13 177 sweep points where develop was correct. All 131 are atN = 1000andN = 1e6, and the selection removes this loss.The
revandfwdderivatives oflbeta. The partial in an argument of at least 10 is now-digamma_diff(a, b). Below 10 it staysdigamma(a) - digamma(a + b), and the two partials sharedigamma(a + b)as before.lbetaitself is accurate at large arguments, but its derivative had the same cancellation. So every model that callslbetawith a large parameter had inaccurate gradients, and so didmulti_student_t_lpdf, which gets itsnugradient by autodiff throughlbeta. Below 10 the plain difference has an absolute error of a feweps, which stays at the rounding level on the log scale too.Changes per function
beta_binomial_lpmf: value bylog_beta_ratio, partials bydigamma_diff.beta_neg_binomial_lpmf: value as-log(n) - lbeta(n, beta) + log((r)_n / (r + alpha + beta)_n) + log((alpha)_r / (alpha + beta)_r), partials bydigamma_diff.neg_binomial_lpmf:alphapartial bydigamma_diff. Thebetapartial termalpha / beta - alpha / (1 + beta)is nowalpha / beta / (1 + beta). The value termlchoose(n + alpha - 1, n)is now-lbeta(alpha, n + 1) - log(n + alpha).neg_binomial_2_lpmf,neg_binomial_2_log_lpmf:phipartial bydigamma_diff. The value termlchoose(n + phi - 1, n)is now-lbeta(phi, n + 1) - log(n + phi). Whenphiis autodiff,neg_binomial_2_lpmfnow evaluateslog(mu + phi)once, and the value and thephipartial both read it; the lazy expression computed thelogtwice per element. The value and every adjoint are bitwise identical before and after this change (2 000 instances, five call types).neg_binomial_2_log_glm_lpmf: value per instance as-lbeta(phi, y + 1) - log(y + phi) - y log1p_exp(log(phi) - theta) - phi log1p_exp(theta - log(phi)), the form ofneg_binomial_2_log_lpmf, instead ofphi log(phi) - lgamma(phi) + lgamma(y + phi) - (y + phi) log(mu + phi) + y theta. The partials do not formexp(theta). Withu = theta - log(phi)ande = exp(-|u|),mu / (mu + phi)is1 / (1 + e)foru > 0ande / (1 + e)otherwise, andphi / (mu + phi)is the other of the two. Thethetapartial isy - (y + phi) mu / (mu + phi), and thephipartial ismu / (mu + phi) - (y / phi) phi / (mu + phi) - log1p_exp(u) + digamma_diff(phi, y)(formulas from @jachymb's review). The value and the partials shareeandlog1p(e):log1p_exp(±u) = max(±u, 0) + log1p(e). With a scalarphiand a vectory, the terms that depend onyonly (lchoose,lgamma(y + 1)underpropto,digamma_diff(phi, y)) are evaluated once per distinct count, throughinternal::per_count_values, if the largest count is at most4 N + 64. This is in the CPU version only.dirichlet_multinomial_lpmf: partials bydigamma_diff.lkj_corr_lpdf(andlkj_corr_cholesky_lpdf,lkj_cov_lpdfthroughdo_lkj_constant): the constant is a sum oflgamma(x + k/2) - lgamma(x). Each term is nowlgamma(k/2) - lbeta(k/2, x), and the code sets theetapartial explicitly withdigamma_diff.yule_simon_{cdf,lcdf,lccdf}:lgamma(alpha + 1) + lgamma(n + 1) - lgamma(n + alpha + 1)is nowlog(n) + lbeta(n, alpha + 1); partial bydigamma_diff.yule_simon_lpmf: valuelog(alpha) + lbeta(n, alpha + 1); partial1 / alpha - digamma_diff(alpha + 1, n).beta_binomial_{cdf,lcdf,lccdf}: the leadinglbeta(nu, mu) - lbeta(alpha, beta)bylog_beta_ratio, the digamma differences bydigamma_diff.beta_neg_binomial_{cdf,lcdf,lccdf}: the leading term is the log pmf atn + 1, now computed as inbeta_neg_binomial_lpmf; partials bydigamma_diff.student_t_lpdf: unchanged fornu < 40. Fornu >= 40, the termslgamma((nu + 1) / 2) - lgamma(nu / 2) - log(nu) / 2anddigamma((nu + 1) / 2) - digamma(nu / 2)come from the asymptotic series inh = nu / 2,-log(2) / 2 - 1/(8h) + 1/(192h^3) - 1/(640h^5) + 17/(14336h^7) - 31/(18432h^9), and its derivative. Against mpmath at 2 012 points fromh = 20to1e15, the errors of the two terms are at most 0.51 and 1.76 eps. The series is also cheaper than twolgammaor twodigammacalls (see "Speed").multi_student_t_lpdf,multi_student_t_cholesky_lpdf: the constantlgamma((nu + p) / 2) - lgamma(nu / 2)is nowlgamma(p / 2) - lbeta(p / 2, nu / 2). The cholesky version sets thenupartial withdigamma_diff(nu / 2, p / 2); the other version gets it throughlbeta.beta_binomial_lpmf,neg_binomial_lpmf,neg_binomial_2_lpmf,neg_binomial_2_log_lpmf,neg_binomial_2_log_glm_lpmf(prim file and kernel) andstudent_t_lpdfcompute the same formulas.Related defects fixed in this PR
lkj_corr_lpdfdroppedd constant / d etaateta == 1.0. The special case foreta == 1returned the constant as a number without a derivative. Ateta = 1withK = 3and the matrix in the new test, develop returnsd/deta = -0.165; the exact value is1.2214.eta = exp(0) = 1is the initial value of a positive parameter withinit = 0.beta_binomial_lcdfcomputedlog(1 - C), withCthe complementary series. Where the cdf is small, this keeps no correct digits, and with the accurateCit can becomelogof a value at or below 0. WhereC > 1/2, the function now uses the mirror relationX <= nif and only ifN - X > N - n - 1.N - Xhas the distributionbeta_binomial(N, beta, alpha). That is the same series with the shapes swapped, without the complement. On develop this function returnedNaNat 16 of 81 sweep points and was wrong by up to 74 at the others. With this PR it returns noNaNthere, and its errors are those of the series (value 7.7e-8, gradient 2.3e-6). Foralpha = 1exactly, the mirrored series is0 / 0at one term, so that case keepslog(1 - C).beta_binomial_lpmfdid not check0 <= n <= N. The code built the check but never computed its result, so the function never returnedLOG_ZERO. Withoutproptothe value was-infby accident (throughbinomial_coefficient_log), but with a nonzero gradient. Underproptoit was finite:-8.216forn = 6,N = 5in the new test. The CPU version returnsLOG_ZEROwithout a gradient, and now the OpenCL version does too.beta_binomial_lpmfwith scalar autodiff shapes did not compile. On develop, the compiler stops at line 81 ofopencl/prim/beta_binomial_lpmf.hppwith "no matching function for call tolbeta(const double&, const double&)". The new test filebeta_binomial_lpmf_scalar_shapes_test.cppcalls the function with scalarvarshapes.neg_binomial_lpmf,neg_binomial_2_lpmfandneg_binomial_2_log_lpmflost the digits ofphiat smallphi. They computedlchoose(n + phi - 1, n)asbinomial_coefficient_log(n + phi - 1, n), which roundsphiinton + phi - 1. The value then has an error of abouteps * n / phi. Atn = 1000,phi = 1e-8, the error is 7.9e-7 (5.0e-9 inneg_binomial_lpmf). Atn = 1,phi = 1e-17, the value is-inf; the exact value is-39.1439. These three functions and the GLM, CPU and OpenCL, now use-lbeta(phi, n + 1) - log(n + phi), and the errors at these points are at most 5.3e-13. The partials were already correct, because they use the exactphi.neg_binomial_2_log_glm_lpmfpartials overflowed at largetheta. On develop, thethetapartialy - exp(theta) (y + phi) / (exp(theta) + phi)isNaNattheta = 720(inf / inf), and-infattheta = 709, whereexp(theta) (y + phi)overflows. The exact value is-1.5at both points (y = 5and 3,phi = 1.5). Theeform in "Changes per function" has no overflow, and its second derivative does not cancel. Aty = 1,phi = 0.07, thefvar<var>Hessian entry inthetais now-4.7225e-17attheta = 35(develop: 0) and-1.40777e-13attheta = 27(develop:-1.40970e-13). A new test checks both.Speed
For
nu < 40,student_t_lpdfcomputes the same formulas as develop, plus the test fornu >= 40. This adds 2.3 % instructions for the value and 3.7 % for value and gradient, and the time is 1.01 and 1.06 times that of develop. Fromnu = 40it executes fewer instructions. Atnu >= 100it executes 72 % fewer for the value and 54 % fewer for value and gradient. The time is 0.33 and 0.54 times that of develop. The instruction counts are fromperf statand valgrind cachegrind, which agree. The times are from the machine below.The table gives the time of this PR divided by the time of develop. Shapes are below 10 unless the row says otherwise. The times are medians of 5 interleaved rounds on one whole node (AMD EPYC 9965, g++ 11.5,
-O2). The spread between rounds is at most 2.8 % for develop and 6.9 % for this PR.neg_binomial,neg_binomial_2,neg_binomial_2_loggradient, counts 0 to 8neg_binomial_2gradient,phifrom 10 to 1e4, counts 0 to 8neg_binomial_2gradient, counts 9 to 100neg_binomial_2gradient, 1000 counts from 0 to 20, onephibeta_binomialgradient,N = 20lbetagradient, both arguments below 10lbetagradient, one argument from 10 to 1000neg_binomial_2_log_glm_lpmfvalue,N = 1000,K = 5, counts with mean 3alpha,betaalpha,beta, scalarphiproptopropto, all 1000 counts distinctpropto, counts from 5000 to 5999alpha,beta, vectorphixWith a scalar
phi, the GLM evaluateslchoose,lgamma(y + 1)anddigamma_diff(phi, y)once per distinct count. Where the counts rarely repeat or exceed4 N + 64, the forms that repair the GLM (items 5 and 6) make it slower than develop.Limits that remain, by a different cause
beta_binomial_{cdf,lcdf,lccdf}stop their3F2series at a term below1e-6. This leaves errors up to2.3e-6in the gradients. The functions also returnNaNor throw at some arguments, for example atbeta = 1, atalpha + beta = 1and at the point in beta_binomial_lpmf is unstable for large shape arguments #2508. Fix and speed up the terminating 3F2 series of the beta_binomial cdfs #3437 repairs these.beta_neg_binomial_{cdf,lcdf,lccdf}stop their series at a term below1e-8. They throw at some arguments from shape1e4and can take seconds per call.beta_neg_binomial_cdfandbeta_neg_binomial_lcdfstill form the complement1 - ccdf, so they are wrong where the cdf is small. With the more accurate log pmf of this PR,1 - ccdfrounds to exactly 0 where the cdf is below about1e-15. On a wide grid of 2 352 points, 1 546 points finished within 2 s on both trees. At 15 of them,beta_neg_binomial_cdfthen returns 0 withNaNgradients. There, develop returns wrong finite values (from -7.2e-11 to 5.4e-11) with finite gradients. Compute the beta_neg_binomial cdfs from sums of the pmf #3441 replaces the series and the complement and repairs all of these.d/dalphaandd/dbeta, and autodiff formsalpha d/dalpha + beta d/dbetaoutside it. For tied shapes in numerical instability in beta_binomial_lpmf at large shape parameters #3153, the two products are-1.5and+1.5, and their sum is27 / s = 54 / exp(lc). Each partial is accurate to a fewepsof its own terms, so the sum is accurate to a fewepsof 1.5, not of its own size.neg_binomial_2_log_lpmfHessian has the quotient-rule cancellation of item 6 at large|eta|(NaNentries ateta = 720and-400,n = 3,phi = 0.07). Develop has the same defect. A follow-up PR can use theeform of the GLM there too.log_rising_factorialis stilllgamma(x + n) - lgamma(x). No Stan Math function calls it. Therevandfwdderivatives oflog_rising_factorial,rising_factorial,log_falling_factorial,falling_factorialandbetastill form a plain digamma difference. A follow-up can use the new helpers there.Tests
test/unit/math/prim/fun/digamma_diff_test.cpp,test/unit/math/mix/fun/digamma_diff_test.cpp: special cases, exact finite sums, 17 mpmath values, the count path and the plain path (digamma_diff(x, 1) == 1 / xexactly fromx = 1e-300to1e300);expect_adat 8 points.test/unit/math/prim/prob/beta_binomial_test.cpp: values at the points of numerical instability in beta_binomial_lpmf at large shape parameters #3153 and beta_binomial_lpmf is unstable for large shape arguments #2508 and at large unequal shapes; the difference to the binomial limit atlc = 42.test/unit/math/rev/prob/beta_binomial_lpmf_test.cpp(new): log-shape gradients at 8 points; thelcgradient of the model in numerical instability in beta_binomial_lpmf at large shape parameters #3153 forlc = 16 ... 32. Fromlc = 34, develop returns exactly 0, which is within1e-13of the exact gradient, so a test there cannot see the defect.test/unit/math/rev/prob/large_shapes_test.cpp(new): 97 rows over the other functions, includingstudent_t_lpdf, bothmulti_student_tfunctions,yule_simon_lpmfandlbeta. For most functions, the rows are points where develop was wrong by more than 100 times the tolerance, plus one point at a small shape where develop was correct. Three kinds of rows differ. Theneg_binomial_lpmfrow at the point of The derivatives of neg_binomial_lpmf are incorrect for large alpha #1578 passes on develop. The GLM rows atphi = 1e-17and1e-8pass on develop too: they check a regression of an earlier commit of this PR. Theyule_simon_cdfand_lcdfrows use a tolerance relative to the reference, because the cdf is1 - cwith a tinyc, and an absolute tolerance cannot see an error inc. The rows include the four negative binomial functions atphi = 1e-8and1e-17and the GLM attheta = 720and709. The file also tests thelkj_corrgradient ateta = 1, andfull - proptoagainst the dropped terms forstudent_t_lpdf,yule_simon_lpmf,beta_neg_binomial_lpmfand three cases of the GLM.test/unit/math/rev/prob/neg_binomial_2_log_glm_lpmf_test.cpp: a vector call against the sum of single-instance calls, value and partials, with and withoutpropto, once with repeated counts (per-count path) and once with a count above4 N + 64.test/unit/math/mix/prob/neg_binomial_2_log_glm_lpmf_test.cpp: thefvar<var>second derivative inthetaattheta = 35and 27.test/unit/math/mix/fun/lbeta_test.cpp: thevarandfvar<double>derivatives oflbetaat arguments from 1e8 to 1e14, in both argument orders, compared asx * d/dxwith mpmath references.test/unit/math/opencl/rev/, because the existing differential tests compare OpenCL with the CPU and cannot see an error that both share. The four negative binomial reference tests include the small-phiand large-thetarows. Thebeta_binomial_lpmfrows are inbeta_binomial_lpmf_reference.hpp:beta_binomial_lpmf_test.cppuses them with vector shapes, andbeta_binomial_lpmf_scalar_shapes_test.cppwith scalar shapes (item 4). Also: a device-function test fordigamma_diff; a test thatbeta_binomial_lpmfgivesLOG_ZEROwithout a gradient fornoutside0...N, also underpropto; and a comparison of the GLM with the CPU for a scalaralphawith a vectorphiand the reverse, atN = 153(more than one work group).Swap tests. CPU: I replaced the 24 changed CPU files that exist on develop with their develop versions, all at once; the new
digamma_diff.hppandlog_rising_factorial_ratio.hppstay. With these files, 7 of the 9 new test cases fail: the 4 newbeta_binomialcases,large_shapes_value_and_log_scale_gradients,lkj_corr_eta_gradient_at_oneand the Hessian test. The other 2 pass, as intended.large_shapes_propto_dropped_termschecksfull - proptoagainst the dropped terms, which develop also satisfies. The GLM vector test checks that a vector call equals the single calls. Inlarge_shapes_test.cpp, each of the 22 function tags has failing assertions. With the branch files restored, all tests pass again. A separate run with the developrevandfwdlbetafiles shows that the newlbetatest fails there too, and the two old tests of that file pass. OpenCL: I replaced the 32 changed files that exist on develop (24 CPU and 8 OpenCL files) with their develop versions. Then every new reference test fails (beta_binomial, the four negative binomial functions,student_t), and so doesopencl_n_outside_support.beta_binomial_lpmf_scalar_shapes_test.cppdoes not compile on develop (item 4). The differential tests pass, but with the CPU files swapped too they compare develop with develop.Full suites. CPU builds on Triton batch nodes, g++ 14.3.0. At the PR head, 56 unit test files of the touched functions pass (
prim,rev,fwd,mix, includinglbeta,digamma_diff,student_t,multi_student_t,lkj_cov,glm_forward_mode_tape_testand the Laplace tests that useneg_binomial_2_log). The generatedtest/probtests ofbeta_binomial,beta_neg_binomial,neg_binomial,neg_binomial_2,yule_simonandstudent_tpass (271 306 cases at64407093ba;neg_binomialandneg_binomial_2again at the head, 23 490 cases). The 9 OpenCL suites of the six distributions,digamma_diffand the kernel generator pass on a V100 (115 cases).make cpplint,make test-math-dependencies,make test-headers, the header checks of the changed files and Doxygen 1.9.7 (no warnings, at64407093ba) pass.Side effects
None
Release notes
Improved stability of
beta_binomial_lpmf,beta_binomial_cdf,beta_binomial_lcdf,beta_binomial_lccdf,beta_neg_binomial_lpmf,beta_neg_binomial_cdf,beta_neg_binomial_lcdf,beta_neg_binomial_lccdf,neg_binomial_lpmf,neg_binomial_2_lpmf,neg_binomial_2_log_lpmf,neg_binomial_2_log_glm_lpmf,dirichlet_multinomial_lpmf,lkj_corr_lpdf,lkj_corr_cholesky_lpdf,lkj_cov_lpdf,student_t_lpdf,multi_student_t_lpdf,multi_student_t_cholesky_lpdf,yule_simon_lpmf,yule_simon_cdf,yule_simon_lcdf,yule_simon_lccdf, and the derivatives oflbeta.Checklist
Copyright holder: Aalto University
The copyright holder is typically you or your assignee, such as a university or company. By submitting this pull request, the copyright holder is agreeing to the license the submitted work under the following licenses:
- Code: BSD 3-clause (https://opensource.org/licenses/BSD-3-Clause)
- Documentation: CC-BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
the basic tests are passing
./runTests.py test/unit)make test-headers)make test-math-dependencies)make doxygen)make cpplint)the code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested