This function computes the number of topics recursively in a backwards fashion. At the final level of the alignment, the path of each topic is the topic index. At intermediate levels, paths are built following the edges with the highest weights from children topics to parent topics.

compute_number_of_paths(aligned_topics, plot = FALSE)

Arguments

aligned_topics

(required) An alignment class with the alignment results.

plot

(optional, default = FALSE) whether to visualize the number of paths.

Value

a data.frame with the number of paths for each model. The n_topics column shows the total possible number of topics available for that model while n_paths gives the number of paths in that model.

Details

Given an alignment object, this function computes the number of paths at each level in the alignment. The result is a data.frame mapping each level to a number from 1 to the number of current levels.

See also

align_topics

Examples

library(purrr)
data <- rmultinom(10, 20, rep(0.1, 20))
lda_params <- setNames(map(1:5, ~ list(k = .)), 1:5)
lda_models <- run_lda_models(data, lda_params)
#> Using default value 'VEM' for 'method' LDA parameter.
#> Using default value 'VEM' for 'method' LDA parameter.
#> Using default value 'VEM' for 'method' LDA parameter.
#> Using default value 'VEM' for 'method' LDA parameter.
#> Using default value 'VEM' for 'method' LDA parameter.
alignment <- align_topics(lda_models)
compute_number_of_paths(alignment, plot = TRUE)

#> # A tibble: 5 × 3
#>   m     n_paths n_topics
#>   <fct>   <int>    <int>
#> 1 1           1        1
#> 2 2           2        2
#> 3 3           3        3
#> 4 4           3        4
#> 5 5           5        5