Skip to contents

This function returns the parent node of the node represented by the node parameter. The result is NULL if node is the root node of its context tree (representing the empty sequence).

Usage

parent(node)

# S3 method for ctx_node
parent(node)

# S3 method for ctx_node_cpp
parent(node)

Arguments

node

a ctx_node object as returned by find_sequence()

Value

a ctx_node object if node does correspond to the empty sequence or NULL when this is not the case

Details

Each node of a context tree represents a sequence. When find_sequence() is called with success, the returned object represents the corresponding node in the context tree. Unless the original sequence is empty, this node has a parent node which is returned as a ctx_node object by the present function. Another interpretation is that the function returns the node object associated to the sequence obtained by removing the oldest value from the original sequence.

Examples

dts <- c(0, 1, 1, 1, 0, 0, 1, 0, 1, 0)
dts_ctree <- ctx_tree(dts, min_size = 1, max_depth = 3)
ctx_00 <- find_sequence(dts_ctree, c(0, 0))
## the parent sequence/node corresponds to the 0 context
parent(ctx_00)
#> Sequence [T]: 0 
#>  followed by 0 (1), 1 (3)
identical(parent(ctx_00), find_sequence(dts_ctree, c(0)))
#> [1] TRUE
## C++ backend
dts <- c(0, 1, 1, 1, 0, 0, 1, 0, 1, 0)
dts_ctree <- ctx_tree(dts, min_size = 1, max_depth = 3, backend = "C++")
ctx_00 <- find_sequence(dts_ctree, c(0, 0))
## the parent sequence/node corresponds to the 0 context
parent(ctx_00)
#> Sequence [T]: 0 
#>  followed by 0 (1), 1 (3)
identical(parent(ctx_00), find_sequence(dts_ctree, c(0)))
#> [1] FALSE