This generic function converts an object into a vlmc.
Usage
as_vlmc(x, ...)
# S3 method for ctx_tree
as_vlmc(x, alpha, cutoff, ...)
# S3 method for tune_vlmc
as_vlmc(x, ...)
Arguments
- x
an object to convert into a vlmc.
- ...
additional arguments for conversion functions.
- alpha
cut off parameter applied during the conversion, quantile scale (if specified)
- cutoff
cut off parameter applied during the conversion, native scale (if specified)
Details
This function converts a context tree into a VLMC. If alpha
or
cutoff
is specified, it is used to reduce the complexity of the tree as in
a direct call to vlmc()
(prune()
).
Examples
## conversion from a context tree
dts <- c(0, 1, 1, 1, 0, 0, 1, 0, 1, 0)
dts_ctree <- ctx_tree(dts, min_size = 1, max_depth = 3)
draw(dts_ctree)
#> *
#> +-- 0
#> | +-- 0
#> | | '-- 1
#> | '-- 1
#> | +-- 0
#> | '-- 1
#> '-- 1
#> +-- 0
#> | +-- 0
#> | '-- 1
#> '-- 1
#> +-- 0
#> '-- 1
dts_vlmc <- as_vlmc(dts_ctree)
class(dts_vlmc)
#> [1] "vlmc" "ctx_tree"
draw(dts_vlmc)
#> * (0.5, 0.5)
#> +-- 0 (0.25, 0.75)
#> | +-- 0 (0, 1)
#> | | '-- 1 (0, 1)
#> | '-- 1 (0.5, 0.5)
#> | +-- 0 (0, 1)
#> | '-- 1 (1, 0)
#> '-- 1 (0.6, 0.4)
#> +-- 0 (0.6667, 0.3333)
#> | +-- 0 (1, 0)
#> | '-- 1 (1, 0)
#> '-- 1 (0.5, 0.5)
#> +-- 0 (0, 1)
#> '-- 1 (1, 0)
## conversion from the result of tune_vlmc
dts <- sample(as.factor(c("A", "B", "C")), 100, replace = TRUE)
tune_result <- tune_vlmc(dts)
tune_result
#> VLMC context tree on A, B, C
#> cutoff: 2.677 (quantile: 0.06879)
#> Number of contexts: 1
#> Maximum context length: 0
#> Selected by BIC (216.1026) with likelihood function "truncated" (-108.7543)
dts_best_vlmc <- as_vlmc(tune_result)
draw(dts_best_vlmc)
#> * (0.34, 0.39, 0.27)