contexts.vlmc {mixvlmc} | R Documentation |
Contexts of a VLMC
Description
This function extracts all the contexts from a fitted VLMC, possibly with some associated data.
Usage
## S3 method for class 'vlmc'
contexts(
ct,
sequence = FALSE,
reverse = FALSE,
frequency = NULL,
positions = FALSE,
local = FALSE,
cutoff = NULL,
metrics = FALSE,
...
)
## S3 method for class 'vlmc_cpp'
contexts(
ct,
sequence = FALSE,
reverse = FALSE,
frequency = NULL,
positions = FALSE,
local = FALSE,
cutoff = NULL,
metrics = FALSE,
...
)
Arguments
ct |
a context tree. |
sequence |
if |
reverse |
logical (defaults to |
frequency |
specifies the counts to be included in the result
data.frame. The default value of |
positions |
logical (defaults to FALSE). Specify whether the positions
of each context in the time series used to build the context tree should be
reported in a |
local |
specifies how the counts reported by |
cutoff |
specifies whether to include the cut off value associated to
each context (see |
metrics |
if TRUE, adds predictive metrics for each context (see
|
... |
additional arguments for the contexts function. |
Details
The default behaviour of the function is to return a list of all the
contexts using ctx_node
objects (as returned by find_sequence()
). The
properties of the contexts can then be explored using adapted functions
such as counts()
, cutoff.ctx_node()
, metrics.ctx_node()
and
positions()
.
When sequence=TRUE
the method returns a data.frame whose first column,
named context
, contains the contexts as vectors (i.e. the value returned
by as_sequence()
applied to a ctx_node
object). Other columns contain
context specific values specified by the additional parameters. Setting any
of those parameters to a value that ask for reporting information will
toggle the result type of the function to data.frame
.
The frequency
parameter is described in details in the documentation of
contexts.ctx_tree()
. When cutoff
is non NULL
, the resulting
data.frame
contains a cutoff
column with the cut off values, either in
quantile or in native scale. See cutoff.vlmc()
and prune.vlmc()
for the
definitions of cut off values and of the two scales.
Value
A list of class contexts
containing the contexts represented in
this tree (as ctx_node
) or a data.frame.
Cut off values
The cut off values reported by contexts.vlmc
can
be different from the ones reported by cutoff.vlmc()
for three reasons:
-
cutoff.vlmc()
reports only useful cut off values, i.e., cut off values that should induce a simplification of the VLMC when used inprune()
. This exclude cut off values associated to simple contexts that are smaller than the ones of their descendants in the context tree. Those values are reported bycontext.vlmc
. -
context.vlmc
reports only cut off values of actual contexts, whilecutoff.vlmc()
reports cut off values for all nodes of the context tree. values are not modified to induce pruning, contrarily to the default behaviour of
cutoff.vlmc()
Positions
A position of a context ctx
in the time series x
is
an index value t
such that the context ends with x[t]
. Thus x[t+1]
is
after the context. For instance if x=c(0, 0, 1, 1)
and ctx=c(0, 1)
(in
standard state order), then the position of ctx
in x
is 3.
State order in a context
Notice that contexts are given by default
in the temporal order and not in the "reverse" order used by many VLMC
research papers: older values are on the left. For instance, the context
c(1, 0)
is reported if the sequence 0, then 1 appeared in the time series
used to build the context tree. Set reverse to TRUE
for the reverse
convention which is somewhat easier to relate to the way the context trees
are represented by draw()
(i.e. recent values at the top the tree).
See Also
find_sequence()
and find_sequence.covlmc()
for direct access to
a specific context, and contexts.ctx_tree()
, contexts.vlmc()
and
contexts.covlmc()
for concrete implementations of contexts()
.
Examples
dts <- sample(as.factor(c("A", "B", "C")), 100, replace = TRUE)
model <- vlmc(dts, alpha = 0.5)
## direct representation with ctx_node objects
model_ctxs <- contexts(model)
model_ctxs
sapply(model_ctxs, cutoff, scale = "quantile")
sapply(model_ctxs, cutoff, scale = "native")
sapply(model_ctxs, function(x) metrics(x)$accuracy)
## data.frame format
contexts(model, frequency = "total")
contexts(model, cutoff = "quantile")
contexts(model, cutoff = "native", metrics = TRUE)