fit.sentopicmodel {sentopics}R 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

## S3 method for class 'sentopicmodel'
fit(
  object,
  iterations = 100,
  nChains = 1,
  displayProgress = TRUE,
  computeLikelihood = TRUE,
  seed = NULL,
  ...
)

## S3 method for class 'multiChains'
fit(
  object,
  iterations = 100,
  nChains = NULL,
  displayProgress = TRUE,
  computeLikelihood = TRUE,
  seed = NULL,
  ...
)

Arguments

object

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

iterations

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

nChains

if set above 1, the model will be fitted multiple times from various starting positions. Latent variables will be re-initialized if object has not been fitted 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.

...

arguments passed to other methods. Not used.

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)
fit(model, 10)

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

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

[Package sentopics version 0.7.3 Index]