parent {mixvlmc}R Documentation

Find the parent of a node in a context tree

Description

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 class 'ctx_node'
parent(node)

## S3 method for class 'ctx_node_cpp'
parent(node)

Arguments

node

a ctx_node object as returned by find_sequence()

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.

Value

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

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)
identical(parent(ctx_00), find_sequence(dts_ctree, c(0)))
## 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)
identical(parent(ctx_00), find_sequence(dts_ctree, c(0)))

[Package mixvlmc version 0.2.1 Index]