fix(stats): keep hidden Markov fitting alive on a single observation
Assisted-by: Qwen 3.8 Flash
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user