add_seq: Add sequence to suffix tree

Description Usage Arguments Value Examples

View source: R/add-seq.R

Description

Adds a sequence to a suffix tree. The sequence can be saved to the suffix tree, as when initially building the tree from a corpus (save = TRUE), or the sequence can be solely tracked in the tree (save = FALSE), as when e.g. making predictions based on the suffix tree. In the latter case, only the tree's active nodes are updated.

Usage

1
2
add_seq(tree, seq, save = TRUE, time = NULL,
  reset_active_nodes = TRUE, terminate = TRUE, visual = FALSE)

Arguments

tree

Suffix tree as produced by new_tree.

seq

Sequence to add, should be a numeric or character vector.

save

Boolean; whether or not to save the sequence in the tree (if save = FALSE, only the active nodes are updated).

time

Either NULL or a numeric vector of timepoints of the same length as seq, which should be in ascending order. If NULL, then defaults to a sequence in steps of 1 beginning from the number of events already in the tree (so, for an empty tree: 0, 1, 2, 3, ...).

reset_active_nodes

By default, the tree's active nodes are reset before adding the new sequence (reset_active_nodes = TRUE). Otherwise the new sequence is treated as a continuation of the previous sequence (reset_active_nodes = FALSE).

terminate

Boolean; ignored if save = FALSE; if TRUE, the terminal symbol is added to the end of the sequence.

visual

Boolean; whether or not to visualize the tree construction process (this is done interactively using the default plotting device).

Value

Returns the updated tree. Updates are done in-place, so it is rarely necessary to save the output of this function.

Examples

1
2
3
4
5
t <- new_tree()
add_seq(t, c("a", "b", "r", "a", "c", "a", "d", "a", "b", "r", "a"), visual = TRUE)
t <- new_tree()
add_seq(t, sample(5, 5, replace = TRUE))
plot(t)

pmcharrison/tst documentation built on May 24, 2019, 7:36 a.m.