grow: Estimate a topic model

View source: R/methods.R

growR Documentation

Estimate a topic model

Description

This function is used to estimate a topic model created by LDA(), JST() or rJST(). In essence, this function iterates a Gibbs sampler MCMC.

Usage

grow(
  x,
  iterations = 100,
  nChains = 1,
  displayProgress = TRUE,
  computeLikelihood = TRUE,
  seed = NULL
)

Arguments

x

a model created with the LDA(), JST() or rJST() function.

iterations

the number of iterations by which the model should be grown.

nChains

if set above 1, the model will be grown into multiple chains. from various starting positions. Latent variables will be re-initialized if x has not been grown before.

displayProgress

if TRUE, a progress bar will be displayed indicating the progress of the computation. When nChains is greater than 1, this requires the package progressr and optionally progress.

computeLikelihood

if set to FALSE, does not compute the likelihood at each iteration. This can slightly decrease the computing time.

seed

for reproducibility, a seed can be provided.

Value

a sentopicmodel of the relevant model class if nChains is unspecified or equal to 1. A multiChains object if nChains is greater than 1.

Parallelism

When nChains > 1, the function can take advantage of future.apply::future_lapply (if installed) to spread the computation over multiple processes. This requires the specification of a parallel strategy using future::plan(). See the examples below.

See Also

LDA(), JST(), rJST(), reset()

Examples

model <- rJST(ECB_press_conferences_tokens)
grow(model, 10)

# -- Parallel computation --
require(future.apply)
future::plan("multisession", workers = 2) # Set up 2 workers
grow(model, 10, nChains = 2)

future::plan("sequential") # Shut down workers

sentopics documentation built on May 18, 2022, 5:05 p.m.