PST何时从左到右,从右到左显示上下文?

时间:2017-03-03 16:22:09

标签: r pst traminer

PST包是否始终显示从右到左的上下文?

query()函数中,我们使用字符串来表示上下文。如果我假设从右到左指定了上下文(因为它似乎在print()cmine()函数中),并且我对序列A->B->C感兴趣,然后我应该查询:

query(S1.p1, "C-B-A")

此外,在predict()函数中,我们使用seqdef()来定义要预测的序列。这是否意味着我应该从左到右指定它们,因为TraMineR通常会这样做?

x <- seqdef("A-B-C)
predict(S1.p1, x)

2 个答案:

答案 0 :(得分:1)

在概率后缀树(PST)中,当我们从根开始读取时,分支从右到左定义后缀。在第一级,您有后缀的最后一个元素,在级别2,您有最后一个元素之前的元素,等等。打印的树显示为左侧的根,并从左向右展开。然而,应该从左到右自然地读取在打印结果的节点中显示的后缀。例如,节点a-b-c表示末尾带有c的后缀。通过在左侧添加b-c,从节点a获得这样的节点。

同样适用于cmine的结果。对于每个找到的上下文, a-b-ccmine给出了在上下文之后立即获取每个可能状态的概率,即在示例中的c之后。

总之,序列和上下文总是从左到右显示,即使上下文是从右到左构建的。

因此,如果您想查询序列A->B->C,请使用query(S1.p1, "A-B-C")。同样,要使用predict预测特定序列,请从左到右自然定义序列。

答案 1 :(得分:1)

应从左到右阅读序列。以下代码提供了对此的验证:

library(PST)
data.seq <- seqdef("A-B-C-D-E-F")
S1.test <- pstree(data.seq, ymin = 0.001, lik = FALSE, with.missing = FALSE)
print(S1.test)

--(e)-[ p=(0.2,0.2,0.2,0.2,0.2,0.2) - n=6 ]
  `--(A)-[ p=(0.001,0.995,0.001,0.001,0.001,0.001) - n=1 ]--| 
  `--(B)-[ p=(0.001,0.001,0.995,0.001,0.001,0.001) - n=1 ]
     `--(A-B)-[ p=(0.001,0.001,0.995,0.001,0.001,0.001) - n=1 ]--| 
  `--(C)-[ p=(0.001,0.001,0.001,0.995,0.001,0.001) - n=1 ]
     `--(B-C)-[ p=(0.001,0.001,0.001,0.995,0.001,0.001) - n=1 ]
        `--(A-B-C)-[ p=(0.001,0.001,0.001,0.995,0.001,0.001) - n=1 ]--| 
  `--(D)-[ p=(0.001,0.001,0.001,0.001,0.995,0.001) - n=1 ]
     `--(C-D)-[ p=(0.001,0.001,0.001,0.001,0.995,0.001) - n=1 ]
        `--(B-C-D)-[ p=(0.001,0.001,0.001,0.001,0.995,0.001) - n=1 ]
           `--(A-B-C-D)-[ p=(0.001,0.001,0.001,0.001,0.995,0.001) - n=1 ]--| 
  `--(E)-[ p=(0.001,0.001,0.001,0.001,0.001,0.995) - n=1 ]
     `--(D-E)-[ p=(0.001,0.001,0.001,0.001,0.001,0.995) - n=1 ]
        `--(C-D-E)-[ p=(0.001,0.001,0.001,0.001,0.001,0.995) - n=1 ]
           `--(B-C-D-E)-[ p=(0.001,0.001,0.001,0.001,0.001,0.995) - n=1 ]
              `--(A-B-C-D-E)-[ p=(0.001,0.001,0.001,0.001,0.001,0.995) - n=1 ]--|


plot(S1.test)

Validation of bottom-to-top reading of plotted tree

它还表明应该从底部到顶部读取绘制的树。