fix(stats): refuse a zero-probability sequence in Viterbi
Assisted-by: GLM 5.3 Flash
This commit is contained in:
@@ -354,6 +354,12 @@ func (m *HiddenMarkovModel) Viterbi(observations []int) (states []int, logProbab
|
||||
arg = k
|
||||
}
|
||||
}
|
||||
if math.IsInf(best, -1) {
|
||||
// Every path has probability zero, the structural zero an
|
||||
// emission or transition carries: the same refusal Forward makes,
|
||||
// not a meaningless path beside a −Inf log probability.
|
||||
return nil, 0, base.Errf("%s: the observation sequence has probability zero under the model", name)
|
||||
}
|
||||
path := make([]int, len(observations))
|
||||
path[len(observations)-1] = arg
|
||||
for t := len(observations) - 1; t > 0; t-- {
|
||||
|
||||
Reference in New Issue
Block a user