Repository navigation
Fix NaN and over/underflow in the HMM functions for long sequences and large log densities (#2677) - #3440
Conversation
The forward pass rescaled only its first column, so on a long sequence the forward probabilities underflowed to 0 and the final normalization computed 0/0. Rescale every forward step, as hmm_latent_rng and hmm_marginal already do. The hidden state probabilities are invariant to a positive factor on each column, so the scale does not need to be kept. log_omegas was also exponentiated directly, so log densities below about -745 underflowed to 0 and large ones overflowed to inf. Subtract the maximum of each column before exponentiating; the hidden state probabilities are invariant to that shift as well. The test hidden_state_prob1 is taken from Charles Margossian's branch bugfix/issue-2677-hmm_hidden_state (e7a5efa).
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.778 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 |
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.859 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 |
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.910 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 |
This comment was marked as resolved.
This comment was marked as resolved.
hmm_latent_rng and hmm_marginal exponentiated log_omegas directly, so log densities below about -745 underflowed to 0 and large ones overflowed to inf, as in hmm_hidden_state_prob before. Subtract the maximum of each column before exponentiating. The sampling probabilities are invariant to the shift. hmm_marginal adds the shifts back to the log density, and its gradients are unchanged because the shift cancels in the adjoint. In hmm_hidden_state_prob, call hmm_check before taking the column maxima, so that a log_omegas with no rows throws instead of hitting an Eigen assert. Fix the docblocks of hmm_hidden_state_prob and hmm_latent_rng, which described log_omegas transposed, and state that the result can still be NaN when the largest density in a column belongs to a state the chain cannot reach. The loops in four hidden state tests skipped the last column.
hmm_check did not check that log_omegas has at least one column. With no columns, n_transitions is -1 and hmm_hidden_state_prob, hmm_latent_rng and hmm_marginal index alphas.col(0) out of bounds. Throw std::invalid_argument instead.
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.657 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 |
|
I've updated the title and description to match the current head, 2a468d6, including @SteveBronder's changes to On the bot's requests:
At 2a468d6, the 19 tests in the four HMM test files pass locally. At the merge base with the same test files, six fail and three abort on an Eigen assert. The description lists them by name. @SteveBronder, is there anything else you need from me before review? |
|
@SteveBronder The only failing check here is
What would you prefer: a Jenkins rerun on the current head (2a468d6), like #3504 got, or should I merge |
|
@SteveBronder Thanks for replaying it. Build 8 never got to the tests, though. Lint and docs passed, and then both "Quick tests" branches (headers and unit) failed cloning |
Fixes #2677.
The fix covers the two causes described below. It has been checked with the tests in this PR. The CmdStan reproducer in the issue comment was last run at 6a70a96, by the review bot, and gave no NaN. It has not been run on the model and data attached in this comment or on the forum thread linked from the issue.
This was assisted by Claude. @SteveBronder wrote the changes to
hmm_latent_rng,hmm_marginalandhmm_check.Summary
hmm_hidden_state_probreturns NaN in two situations, both described in #2677:alphas.col(0). Every later column is the product ofomegasand the previous column, so it shrinks like the joint densityp(y_1, ..., y_n). Once that falls below the smallest double (a log density of about -745), the column is exactly 0, and the normalizationalphas.col(n) /= alphas.col(n).sum()computes 0/0. In the reproducer (2 states, Gaussian observations) the first NaN appears at t = 472, for every T beyond that.omegas = exp(log_omegas)underflows to 0 for entries below about -745 and overflows to inf above about 709. This is what @charlesm93 found in 2022 withlog_omegasat 1000 or -1000.hmm_latent_rngandhmm_marginalalready rescale their forward passes, so they don't have the first problem, but they do exponentiatelog_omegasdirectly and have the second.The fix:
hmm_hidden_state_prob: each column is now divided by its maximum, as the backward pass in this function already does and as the forward passes ofhmm_latent_rngandhmm_marginalalready do. The hidden state probabilities are invariant to a positive factor on each column ofalphas, so unlikehmm_marginalthe scale does not need to be kept.log_omegasis shifted by its maximum before it is exponentiated.hmm_hidden_state_probandhmm_latent_rngthe probabilities are invariant to the shift.hmm_marginaladds the shifts back to the log density. Its gradients are unchanged because the shift cancels in the adjoint.hmm_check: it now rejects alog_omegaswith no columns, which otherwise indexesalphas.col(0)out of bounds.hmm_hidden_state_probnow callshmm_checkbefore taking the column maxima.hmm_hidden_state_probandhmm_latent_rngdescribedlog_omegastransposed and are corrected.The backward pass is unchanged. The cost stays at O(K^2) per step, with no transcendental functions in the loop. A recursion fully on the log scale (with
log_sum_exp) would also work, but it needs K^2exp/logcalls per step, and the rescaled form matches the existing HMM functions.@charlesm93 started
bugfix/issue-2677-hmm_hidden_statein 2022. It has one commit, e7a5efa, which adds the testhidden_state_prob1(log_omegas= 1000,Gammasending every state to state 1) and no fix. The branch is 3,572 commits behinddevelop, so this PR is opened from a fresh branch, and that test is included here with its original name and assertions.Tests
New tests, plus a reference implementation in
hmm_hidden_state_prob_test.cpp:hmm_hidden_state_prob_log_space, which runs forward-backward entirely on the log scale withlog_sum_exp.hmm_hidden_state_prob_test.cpp:hidden_state_long_sequence: simulates a 2-state Gaussian HMM with 5000 observations (Gamma = [[0.95, 0.05], [0.10, 0.90]], means +1/-1, sd 1,boost::random::mt19937seeded at 2677). It checks thathmm_marginalis below -2000, so the old forward pass must underflow. It then asserts that every output is finite, that every column sums to 1 within 1e-12, and that the output matches the log scale reference within 1e-10.hidden_state_very_negative_log_omegas: subtracts1000 + 10 nfrom column n of the fixture'slog_omegas, so every entry is below -1000. It asserts that the output is finite, equals the output for the unshiftedlog_omegaswithin 1e-12, and matches the log scale reference within 1e-10. The reference tolerance is looser because a log scale computation loses about machine epsilon times the magnitude of the log densities.hidden_state_prob1: taken from @charlesm93's branch (log_omegas= 1000, overflow).hidden_state_neg_inf_log_omega: a single-infentry gives probability 0 for that state, with a finite result that matches the log scale reference within 1e-12.hidden_state_no_states_throwsandhidden_state_no_observations_throws: emptylog_omegasthrow.hmm_latent_rng_test.cpp:latent_rng_shifted_log_omegas: with shifts of -1000 and 1000 per column (plus10 n) and the same seed, 100 draws match the draws for the unshiftedlog_omegas.latent_rng_no_observations_throws: alog_omegaswith no columns throws.hmm_marginal_test.cpp:shifted_log_omegas: with the same shifts, the log density changes by the total shift and the gradients match the unshifted ones within 1e-10.exceptions: gains a case for alog_omegaswith no columns.hmm_check_test.cpp:hmm_check: gains the same case.Results of the four test files at 2a468d6, and at the merge base e4745c8 with the same test files copied in (g++ 16.2.1,
O=0):hidden_state_long_sequence,hidden_state_very_negative_log_omegas,hidden_state_prob1,latent_rng_shifted_log_omegas,shifted_log_omegasandhmm_check.hidden_state_no_observations_throws,latent_rng_no_observations_throwsandexceptions, all on alog_omegaswith no columns.hidden_state_neg_inf_log_omegaandhidden_state_no_states_throws, which guard against regressions from the shift.CI is green at 2a468d6.
Side Effects
Long sequences and log densities of large magnitude, which used to give NaN from
hmm_hidden_state_prob, now give finite probabilities. The large-magnitude case is also handled inhmm_latent_rngandhmm_marginal.The result of
hmm_hidden_state_probcan still be NaN in two cases:log_omegasis entirely-inf.For inputs that already gave finite results, the shift and the rescaling do not change the output in exact arithmetic, so any difference is rounding. The existing tests pass unchanged, but no test compares the output directly with
develop's.A
log_omegaswith no columns now throwsstd::invalid_argumentfrom all three functions, throughhmm_check. Before, it hit an Eigen assert, or read out of bounds with asserts disabled.Release notes
hmm_hidden_state_probno longer returns NaN for long sequences or for log densities of large magnitude.hmm_latent_rngandhmm_marginalno longer underflow or overflow for log densities of large magnitude. All three now throwstd::invalid_argumentiflog_omegashas no columns.Checklist
Copyright holder: Aleksandr Tarutin
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): the four HMM test files were run locally at 2a468d6, not all oftest/unitmake test-headers): not re-run locally since the latest commitsmake test-math-dependencies): not run locallymake doxygen): not run locallymake cpplint): not re-run locally since the latest commitsthe code is written in idiomatic C++ and changes are documented in the doxygen
the new changes are tested
🤖 Generated with Claude Code