hmm_states.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:siHMM 作者: Ardavans 项目源码 文件源码
def _sample_forwards_log(self, betal, trans_matrix, init_state_distn, log_likelihoods_loglinear):
        errs = np.seterr(over='ignore')
        Al = trans_matrix
        aBl = log_likelihoods_loglinear
        T = aBl.shape[0]
        pil = init_state_distn
        nhs = trans_matrix.shape[0]
        giant_Al_pil = np.tile(np.vstack((np.tile(pil, (nhs,1)), Al )), (1,2))
        stateseq = np.empty(T,dtype=np.int32)
        true_segmentation = np.ones(T,dtype=np.int32)
        nextstate_unsmoothed = np.tile(init_state_distn, 2)

        for idx in xrange(T):
            logdomain = betal[idx] + aBl[idx] ###check this for the initial and last state and compare with the forward message
            logdomain[nextstate_unsmoothed == 0] = -np.inf

            if np.any(np.isfinite(logdomain)):
                stateseq[idx] = sample_discrete(nextstate_unsmoothed * np.exp(logdomain - np.amax(logdomain)))
            else:
                stateseq[idx] = sample_discrete(nextstate_unsmoothed)
            if stateseq[idx] < nhs: true_segmentation[idx] = 0
            nextstate_unsmoothed = giant_Al_pil[stateseq[idx]]

        return stateseq, true_segmentation
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号