fix(stats): keep hidden Markov fitting alive on a single observation

Assisted-by: Qwen 3.8 Flash
This commit is contained in:
2026-09-27 14:23:51 +02:00
parent 2764a18075
commit e507adeb64
3 changed files with 47 additions and 0 deletions
+9
View File
@@ -524,6 +524,15 @@ func hmmReestimate(model *HiddenMarkovModel, observations []int, gamma, xi [][]f
for j := range states {
den += transition[k*states+j]
}
if den == 0 {
// No transition evidence reached this row, the single-
// observation sequence being the case in point: dividing the
// zero fills the row with NaN the constructor refuses, and
// the sweep after it crashed on the nil model that refusal
// left. The row keeps its previous estimate instead.
copy(transition[k*states:(k+1)*states], model.Transition[k*states:(k+1)*states])
continue
}
for j := range states {
transition[k*states+j] = math.Max(transition[k*states+j]/den, hmmFloor)
}