Repository navigation
Conversation
Contributor
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: 1496.356 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 |
Contributor
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: 46 bits physical, 48 bits virtual CPU(s): 80 On-line CPU(s) list: 0-79 Thread(s) per core: 2 Core(s) per socket: 20 Socket(s): 2 NUMA node(s): 2 Vendor ID: GenuineIntel CPU family: 6 Model: 85 Model name: Intel(R) Xeon(R) Gold 6248 CPU @ 2.50GHz Stepping: 7 CPU MHz: 999.611 CPU max MHz: 3900.0000 CPU min MHz: 1000.0000 BogoMIPS: 5000.00 Virtualization: VT-x L1d cache: 1.3 MiB L1i cache: 1.3 MiB L2 cache: 40 MiB L3 cache: 55 MiB NUMA node0 CPU(s): 0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62,64,66,68,70,72,74,76,78 NUMA node1 CPU(s): 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59,61,63,65,67,69,71,73,75,77,79 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Indirect target selection: Mitigation; Aligned branch/return thunks Vulnerability Itlb multihit: KVM: Mitigation: Split huge pages Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Old microcode: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Mitigation; Enhanced IBRS Vulnerability Spec rstack overflow: Not affected 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; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop Vulnerability Srbds: Not affected Vulnerability Tsa: Not affected Vulnerability Tsx async abort: Mitigation; TSX disabled 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 dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 intel_ppin ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req vnmi pku ospke avx512_vnni md_clear flush_l1d arch_capabilities 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 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the skew normal item of #3364.
This PR improves the accuracy and speed of
skew_normal_lcdfandskew_normal_lccdf.#3364 suggested deriving
skew_normal_lcdfandskew_normal_lccdffromstd_log_lcdf, but does not fit that pattern and the skew normal tail needs its own computation.This PR was assisted by Claude
Summary
skew_normal_lcdfandskew_normal_lccdfcomputed the probability on the linear scale and then took the log, so the error of the log probability was about1e-16 / P. On a grid of 2079 points (z = (y - mu) / sigmafrom -100 to 100,alphafrom -1000 to 1000) both functions were accurate forlog P >= -20, and fromlog P ≈ -31on they returned wrong values (for exampleskew_normal_lcdf(-1 | 0, 1, 10)= -38.12, true -58.59), location and scale gradients that were exactly 0,NaNand-inf. References: mpmath at 40 digits, two independent integral representations of the tail probability without subtraction, which agree to 1e-37.There were two causes:
Phi(z) - 2 T(z, alpha)(Tis Owen's T function) cancels on the short-tail side,z < 0, alpha > 0: the relative error is about1e-16 exp((alpha z)^2 / 2). The lccdf has the mirror defect forz > 0, alpha < 0. The gradients also used1 + erf(alpha z / sqrt(2)), which is 0 there.skew_normal_lccdfcomputed1 - Phi(z)by subtraction: wrong fromz = 8for everyalpha, and-inffromz = 9foralpha <= 0(atalpha = 0the defect of Errors when right-censoring: bug in normal_lccdf? #2847).Changes:
skew_normal_lccdf(y | mu, sigma, alpha)is computed asskew_normal_lcdf(-y | -mu, sigma, -alpha), because-X ~ SkewNormal(-mu, sigma, -alpha), asnormal_lccdfdoes since Aligned normal_lccdf and std_normal_lccdf with the lcdf functions #3363. This removes cause 2 and the duplicated code, and every repair of the lcdf now also repairs the lccdf. The arguments are negated withminus(), which keeps avar_value<Eigen::Matrix>a matrix. The implementation isinternal::skew_normal_lcdf_impl<func>, wherefuncis the function name in error messages; the public signatures do not change.skew_normal_lcdfuses three exact representations, so that no large cancellation remains:z < 0, alpha > 0, alpha |z| >= 2.5:log F = -z^2 (1 + alpha^2) / 2 - log(pi z^2 alpha (1 + alpha^2)) + log J, withJ = int_0^inf exp(-w) / ((1 + w / d2) sqrt(1 + w / d1)) dw,d1 = (alpha z)^2 / 2,d2 = z^2 (1 + alpha^2) / 2.Jlies in(0, 1]and is smooth; a 23-node Gauss-Laguerre rule gives it to 8e-15 atalpha |z| = 2.5and to 2e-17 fromalpha |z| = 3. The gradients ared/dz log F = |z| (1 + alpha^2) M(alpha |z|) / JwithM(x) = sqrt(pi / 2) x erfcx(x / sqrt(2)), andd/dalpha log F = -z^2 alpha / J. Nothing underflows, so this branch also works belowz = -38.5. The form follows fromF = (1 / pi) int_alpha^inf exp(-z^2 (1 + t^2) / 2) / (1 + t^2) dtwithw = z^2 (t^2 - alpha^2) / 2;alpha > 1otherwise:F = 2 T(alpha |z|, 1 / alpha) + Phi(alpha z) erf(z / sqrt(2)), from Owen's identityT(h, a) + T(a h, 1 / a) = Phi(h) / 2 + Phi(a h) / 2 - Phi(h) Phi(a h). Forz >= 0both terms are positive; forz < 0the cancellation factor stays below about 30 foralpha >= 2, independent ofalpha;alpha <= 1otherwise:Phi(z) - 2 T(z, alpha)as before; there the cancellation factor is at most about 200.exp(log numerator - log F), becauseexp(-z^2 / 2)andexp(-z^2 (1 + alpha^2) / 2)can be subnormal or 0 where their ratio to the cdf is not. The function now loops over the elements, asnormal_lcdfdoes.Could not find any library that computes this tail with relative accuracy: Boost and SciPy use
Phi - 2T, and the bivariate normal method of Komelj (2023) is accurate in absolute terms.Worst relative error on the grid, tail side (
P < 1/2), / number of gross failures (NaN,inf, an exact 0 where the true value is above 1e-8, or a relative error above 1e-3):log PThe lccdf of this PR has the same errors as its lcdf (mirror). On a second set of 1952 points around the switches, the short-tail branch is within 6e-16 (value) and 6e-15 (gradients), also below
log P = -700.Time per call (ns, Xeon E5-2680 v3, 4096 points per region, three interleaved rounds, spread at most 1 %); ratio = before / this PR (bigger is better):
varwith gradient (lcdf / lccdf)|z| < 2,|alpha| < 3)alpha |z|from 3 to 10)alphafrom 1.3 to 100, outside the short tail|alpha| < 1owens_tdominates the cost: the short-tail branch calls none, and the second branch calls it with1 / alpha < 1, which Boost evaluates without its own reflection.Limits that remain
z < -38.5withalpha < 0.065(includingalpha <= 0) the probability still underflows (log P < -700), as innormal_lcdfon develop.alpha <= 1branch the gradients keep errors up to about 5e-13 nearalpha |z| = 2.5at large|z|: the cancellation factor times the relative error of Owen's T andPhithere. Theexp(log numerator - log F)form costs about|log F| * 1e-16relative (at most 1.6e-13 atlog P = -700).skew_normal_cdf(linear scale) is not changed.Tests
test/unit/math/rev/prob/skew_normal_lcdf_test.cpp: the value and the four partials against mpmath references at 15 points (9 in the short tail, includingz = -40andalpha = 1e4; 3 withalpha > 1and 3 withalpha <= 1outside it), a vectorized call over the three branches, and infinitey; relative tolerance 1e-12.test/unit/math/rev/prob/skew_normal_lccdf_test.cpp: the upper tail (8 points,zfrom 8 to 35), the short tail of the lccdf (4 points), 3 bulk points, a vectorized call, and the function names in error messages. The row check of both files is inskew_normal_cdf_test_helpers.hpp.test/prob/skew_normalpass (145 314 cases in 156 binaries, including thevar_value<Eigen::Matrix>cases).Side Effects
At infinite
ythe partials are now 0. Before, they wereNaNaty = -inf(0 / 0) and, foralpha = 0, aty = +inf.Release notes
Improved the accuracy and speed of
skew_normal_lcdfandskew_normal_lccdf.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