class_docstr: Estimate Dynamic Topic Model parameters based on a training corpus.
class_docstr_tok: ["Estimate","Dynamic","Topic","Model","parameters","based","on","a","training","corpus","."]
docstr: Fit a LDA Sequence model (DTM).
  
  This method will iteratively setup LDA models and perform EM steps until the sufficient statistics convergence,
  or until the maximum number of iterations is reached. Because the true posterior is intractable, an
  appropriately tight lower bound must be used instead. This function will optimize this bound, by minimizing
  its true Kullback-Liebler Divergence with the true posterior.
  
  Parameters
  ----------
  corpus : {iterable of list of (int, float), scipy.sparse.csc}
      Stream of document vectors or sparse matrix of shape (`num_documents`, `num_terms`).
  lda_inference_max_iter : int
      Maximum number of iterations for the inference step of LDA.
  em_min_iter : int
      Minimum number of time slices to be inspected.
  em_max_iter : int
      Maximum number of time slices to be inspected.
  chunksize : int
      Number of documents to be processed in each chunk.
  
  Returns
  -------
  float
      The highest lower bound for the true posterior produced after all iterations.
docstr_tok: ["Fit","a","LDA","Sequence","model","(","DTM",")",".","This","method","will","iteratively","setup","LDA","models","and","perform","EM","steps","until","the","sufficient","statistics","convergence",",","or","until","the","maximum","number","of","iterations","is","reached",".","Because","the","true","posterior","is","intractable",",","an","appropriately","tight","lower","bound","must","be","used","instead",".","This","function","will","optimize","this","bound",",","by","minimizing","its","true","Kullback-Liebler","Divergence","with","the","true","posterior",".","Parameters","--","--","--","--","--","corpus",":","{","iterable","of","list","of","(","int",",","float",")",",","scipy.sparse.csc","}","Stream","of","document","vectors","or","sparse","matrix","of","shape","(","`","num_documents","`",",","`","num_terms","`",")",".","lda_inference_max_iter",":","int","Maximum","number","of","iterations","for","the","inference","step","of","LDA",".","em_min_iter",":","int","Minimum","number","of","time","slices","to","be","inspected",".","em_max_iter",":","int","Maximum","number","of","time","slices","to","be","inspected",".","chunksize",":","int","Number","of","documents","to","be","processed","in","each","chunk",".","Returns","--","--","--","-","float","The","highest","lower","bound","for","the","true","posterior","produced","after","all","iterations","."]
code: def fit_lda_seq(
      self,
      corpus,
      lda_inference_max_iter,
      em_min_iter,
      em_max_iter,
      chunksize,
  ):
      """Fit a LDA Sequence model (DTM).
  
      This method will iteratively setup LDA models and perform EM steps until the sufficient statistics convergence,
      or until the maximum number of iterations is reached. Because the true posterior is intractable, an
      appropriately tight lower bound must be used instead. This function will optimize this bound, by minimizing
      its true Kullback-Liebler Divergence with the true posterior.
  
      Parameters
      ----------
      corpus : {iterable of list of (int, float), scipy.sparse.csc}
          Stream of document vectors or sparse matrix of shape (`num_documents`, `num_terms`).
      lda_inference_max_iter : int
          Maximum number of iterations for the inference step of LDA.
      em_min_iter : int
          Minimum number of time slices to be inspected.
      em_max_iter : int
          Maximum number of time slices to be inspected.
      chunksize : int
          Number of documents to be processed in each chunk.
  
      Returns
      -------
      float
          The highest lower bound for the true posterior produced after all iterations.
  
      """
      LDASQE_EM_THRESHOLD = 1e-4
      # if bound is low, then we increase iterations.
      LOWER_ITER = 10
      ITER_MULT_LOW = 2
      MAX_ITER = 500
  
      num_topics = self.num_topics
      vocab_len = self.vocab_len
      data_len = self.num_time_slices
      corpus_len = self.corpus_len
  
      bound = 0
      convergence = LDASQE_EM_THRESHOLD + 1
      iter_ = 0
  
      while iter_ < em_min_iter or (
          (convergence > LDASQE_EM_THRESHOLD) and iter_ <= em_max_iter
      ):
          logger.info(" EM iter %i", iter_)
          logger.info("E Step")
          # TODO: bound is initialized to 0
          old_bound = bound
  
          # initiate sufficient statistics
          topic_suffstats = []
          for topic in range(num_topics):
              topic_suffstats.append(np.zeros((vocab_len, data_len)))
  
          # set up variables
          gammas = np.zeros((corpus_len, num_topics))
          lhoods = np.zeros((corpus_len, num_topics + 1))
          # compute the likelihood of a sequential corpus under an LDA
          # seq model and find the evidence lower bound. This is the E - Step
          bound, gammas = self.lda_seq_infer(
              corpus,
              topic_suffstats,
              gammas,
              lhoods,
              iter_,
              lda_inference_max_iter,
              chunksize,
          )
          self.gammas = gammas
  
          logger.info("M Step")
  
          # fit the variational distribution. This is the M - Step
          topic_bound = self.fit_lda_seq_topics(topic_suffstats)
          bound += topic_bound
  
          if (bound - old_bound) < 0:
              # if max_iter is too low, increase iterations.
              if lda_inference_max_iter < LOWER_ITER:
                  lda_inference_max_iter *= ITER_MULT_LOW
              logger.info(
                  "Bound went down, increasing iterations to %i",
                  lda_inference_max_iter,
              )
  
          # check for convergence
          convergence = np.fabs((bound - old_bound) / old_bound)
  
          if convergence < LDASQE_EM_THRESHOLD:
              lda_inference_max_iter = MAX_ITER
              logger.info(
                  "Starting final iterations, max iter is %i",
                  lda_inference_max_iter,
              )
              convergence = 1.0
  
          logger.info(
              "iteration %i iteration lda seq bound is %f convergence is %f",
              iter_,
              bound,
              convergence,
          )
  
          iter_ += 1
  
      return bound
  
imports: import logging
  import numpy
  from scipy.special import digamma, gammaln
  from scipy import optimize
  from gensim import utils, matutils
  from gensim.models import ldamodel
label_desc: Use image node_id 3 for calling the LdaSeqModel obj's underlying member method code with example usage: obj.fit_lda_seq(corpus, lda_inference_max_iter, em_min_iter, em_max_iter, chunksize) and returns: bound