ToyHMMK4.py 文件源码

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

项目:bnpy 作者: bnpy 项目源码 文件源码
def plot_sequence(seqID, Data, dimID=0, maxT=200):
    Xseq = Data.X[Data.doc_range[seqID]:Data.doc_range[seqID + 1]]
    Zseq = Data.TrueParams['Z'][
        Data.doc_range[seqID]:Data.doc_range[
            seqID +
            1]]

    Xseq = Xseq[:maxT, dimID]  # Xseq is 1D after this statement!
    Zseq = Zseq[:maxT]

    # Plot X, colored by segments Z
    changePts = np.flatnonzero(np.abs(np.diff(Zseq)))
    changePts = np.hstack([0, changePts + 1])
    for ii, loc in enumerate(changePts[:-1]):
        nextloc = changePts[ii + 1]
        ts = np.arange(loc, nextloc)
        xseg = Xseq[loc:nextloc]
        kseg = int(Zseq[loc])

        color = GaussViz.Colors[kseg % len(GaussViz.Colors)]
        pylab.plot(ts, xseg, '.-', color=color, markersize=8)
        pylab.plot(
            [nextloc - 1, nextloc], [Xseq[nextloc - 1], Xseq[nextloc]], 'k:')
    pylab.ylim([-2, 14])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号