PST什么时候从左到右和从右到左显示上下文?

When does PST display contexts from left to right and right to left?

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)

?

在概率后缀树 (PST) 中,当我们从根开始读取后缀时,分支定义了从右到左的后缀。在第一层,您有后缀的最后一个元素,在第二层,您有最后一个元素之前的元素,等等。打印的树显示为根在左侧,并从左到右展开。尽管如此,打印结果节点中显示的后缀应该自然地从左到右阅读。例如,节点 a-b-c 表示末尾带有 c 的后缀。这样的节点是从节点b-c左边加上a得到的

cmine的结果也是如此。对于每个找到的上下文,例如a-b-ccmine 给出了在上下文之后立即获得每个可能状态的概率,即在示例中的 c 之后。

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

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

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

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)

这也表明绘制的树应该从下到上阅读。