camrinbraun / HMMoce

hidden markov model for psat data v.1.1
Other
6 stars 7 forks source link

Prevent fac == 0 in hmm.smoother #66

Open camrinbraun opened 2 years ago

camrinbraun commented 2 years ago

From Dr. Itoh:

When fac become too low, error occur and the program stop. I added a sentence and prevent to the fac become zero. I don't know the statistical accuracy of this measure. I am doing so tentatively to get the calculated value.

<>

    else {

        post1 <- post1 * f$phi[1, t - 1, , ]

        post2 <- post2 * f$phi[2, t - 1, , ]

        fac <- sum(as.vector(post1)) + sum(as.vector(post2))

        smooth[1, t - 1, , ] <- post1/fac

        smooth[2, t - 1, , ] <- post2/fac

<>

        post1 <- post1 * f$phi[1, t - 1, , ]

        post2 <- post2 * f$phi[2, t - 1, , ]

        fac <- sum(as.vector(post1)) + sum(as.vector(post2))

        if(fac< 1e-200) {

               fac <- 1e-200       #added to prevent fac=0 which cause error.

        }

        smooth[1, t - 1, , ] <- post1/fac

        smooth[2, t - 1, , ] <- post2/fac
camrinbraun commented 2 years ago

@marosteg @galuardi have you had this issue?

marosteg commented 2 years ago

I've never run into that problem.