class_docstr: Train and use Online Latent Dirichlet Allocation model as presented in
  `'Online Learning for LDA' by Hoffman et al.`_
  
  Examples
  -------
  Initialize a model using a Gensim corpus
  
  .. sourcecode:: pycon
  
      >>> from gensim.test.utils import common_corpus
      >>>
      >>> lda = LdaModel(common_corpus, num_topics=10)
  
  You can then infer topic distributions on new, unseen documents.
  
  .. sourcecode:: pycon
  
      >>> doc_bow = [(1, 0.3), (2, 0.1), (0, 0.09)]
      >>> doc_lda = lda[doc_bow]
  
  The model can be updated (trained) with new documents.
  
  .. sourcecode:: pycon
  
      >>> # In practice (corpus =/= initial training corpus), but we use the same here for simplicity.
      >>> other_corpus = common_corpus
      >>>
      >>> lda.update(other_corpus)
  
  Model persistency is achieved through :meth:`~gensim.models.ldamodel.LdaModel.load` and
  :meth:`~gensim.models.ldamodel.LdaModel.save` methods.
class_docstr_tok: ["Train","and","use","Online","Latent","Dirichlet","Allocation","model","as","presented","in","`","'Online","Learning","for","LDA","'","by","Hoffman","et","al.","`","_","Examples","--","--","--","-","Initialize","a","model","using","a","Gensim","corpus","..","sourcecode",":",":","pycon",">",">",">","from","gensim.test.utils","import","common_corpus",">",">",">",">",">",">","lda","=","LdaModel","(","common_corpus",",","num_topics=10",")","You","can","then","infer","topic","distributions","on","new",",","unseen","documents",".","..","sourcecode",":",":","pycon",">",">",">","doc_bow","=","[","(","1",",","0.3",")",",","(","2",",","0.1",")",",","(","0",",","0.09",")","]",">",">",">","doc_lda","=","lda","[","doc_bow","]","The","model","can","be","updated","(","trained",")","with","new","documents",".","..","sourcecode",":",":","pycon",">",">",">","#","In","practice","(","corpus","=\/=","initial","training","corpus",")",",","but","we","use","the","same","here","for","simplicity",".",">",">",">","other_corpus","=","common_corpus",">",">",">",">",">",">","lda.update","(","other_corpus",")","Model","persistency","is","achieved","through",":","meth",":","`","~gensim.models.ldamodel.LdaModel.load","`","and",":","meth",":","`","~gensim.models.ldamodel.LdaModel.save","`","methods","."]
docstr: Estimate the variational bound of documents from the corpus as E_q[log p(corpus)] - E_q[log q(corpus)].
  
  Parameters
  ----------
  corpus : iterable of list of (int, float), optional
      Stream of document vectors or sparse matrix of shape (`num_documents`, `num_terms`) used to estimate the
      variational bounds.
  gamma : numpy.ndarray, optional
      Topic weight variational parameters for each document. If not supplied, it will be inferred from the model.
  subsample_ratio : float, optional
      Percentage of the whole corpus represented by the passed `corpus` argument (in case this was a sample).
      Set to 1.0 if the whole corpus was passed.This is used as a multiplicative factor to scale the likelihood
      appropriately.
  
  Returns
  -------
  numpy.ndarray
      The variational bound score calculated for each document.
docstr_tok: ["Estimate","the","variational","bound","of","documents","from","the","corpus","as","E_q","[","log","p","(","corpus",")","]","-","E_q","[","log","q","(","corpus",")","]",".","Parameters","--","--","--","--","--","corpus",":","iterable","of","list","of","(","int",",","float",")",",","optional","Stream","of","document","vectors","or","sparse","matrix","of","shape","(","`","num_documents","`",",","`","num_terms","`",")","used","to","estimate","the","variational","bounds",".","gamma",":","numpy.ndarray",",","optional","Topic","weight","variational","parameters","for","each","document",".","If","not","supplied",",","it","will","be","inferred","from","the","model",".","subsample_ratio",":","float",",","optional","Percentage","of","the","whole","corpus","represented","by","the","passed","`","corpus","`","argument","(","in","case","this","was","a","sample",")",".","Set","to","1.0","if","the","whole","corpus","was","passed.This","is","used","as","a","multiplicative","factor","to","scale","the","likelihood","appropriately",".","Returns","--","--","--","-","numpy.ndarray","The","variational","bound","score","calculated","for","each","document","."]
code: def bound(self, corpus, gamma=None, subsample_ratio=1.0):
      """Estimate the variational bound of documents from the corpus as E_q[log p(corpus)] - E_q[log q(corpus)].
  
      Parameters
      ----------
      corpus : iterable of list of (int, float), optional
          Stream of document vectors or sparse matrix of shape (`num_documents`, `num_terms`) used to estimate the
          variational bounds.
      gamma : numpy.ndarray, optional
          Topic weight variational parameters for each document. If not supplied, it will be inferred from the model.
      subsample_ratio : float, optional
          Percentage of the whole corpus represented by the passed `corpus` argument (in case this was a sample).
          Set to 1.0 if the whole corpus was passed.This is used as a multiplicative factor to scale the likelihood
          appropriately.
  
      Returns
      -------
      numpy.ndarray
          The variational bound score calculated for each document.
  
      """
      score = 0.0
      _lambda = self.state.get_lambda()
      Elogbeta = dirichlet_expectation(_lambda)
  
      for d, doc in enumerate(
          corpus
      ):  # stream the input doc-by-doc, in case it's too large to fit in RAM
          if d % self.chunksize == 0:
              logger.debug("bound: at document #%i", d)
          if gamma is None:
              gammad, _ = self.inference([doc])
          else:
              gammad = gamma[d]
          Elogthetad = dirichlet_expectation(gammad)
  
          assert gammad.dtype == self.dtype
          assert Elogthetad.dtype == self.dtype
  
          # E[log p(doc | theta, beta)]
          score += sum(
              cnt * logsumexp(Elogthetad + Elogbeta[:, int(id)])
              for id, cnt in doc
          )
  
          # E[log p(theta | alpha) - log q(theta | gamma)]; assumes alpha is a vector
          score += np.sum((self.alpha - gammad) * Elogthetad)
          score += np.sum(gammaln(gammad) - gammaln(self.alpha))
          score += gammaln(np.sum(self.alpha)) - gammaln(np.sum(gammad))
  
      # Compensate likelihood for when `corpus` above is only a sample of the whole corpus. This ensures
      # that the likelihood is always roughly on the same scale.
      score *= subsample_ratio
  
      # E[log p(beta | eta) - log q (beta | lambda)]; assumes eta is a scalar
      score += np.sum((self.eta - _lambda) * Elogbeta)
      score += np.sum(gammaln(_lambda) - gammaln(self.eta))
  
      if np.ndim(self.eta) == 0:
          sum_eta = self.eta * self.num_terms
      else:
          sum_eta = np.sum(self.eta)
  
      score += np.sum(gammaln(sum_eta) - gammaln(np.sum(_lambda, 1)))
  
      return score
  
imports: import logging
  import numbers
  import os
  import time
  from collections import defaultdict
  import numpy
  from scipy.special import gammaln, psi
  from scipy.special import polygamma
  from gensim import interfaces, utils, matutils
  from gensim.matutils import kullback_leibler, hellinger, jaccard_distance, jensen_shannon, dirichlet_expectation, logsumexp, mean_absolute_difference
  from gensim.models import basemodel, CoherenceModel
  from gensim.models.callbacks import Callback
label_desc: Use image node_id 13 for calling the LdaModel obj's underlying member method code with example usage: obj.bound(corpus, gamma, subsample_ratio) and returns: score