class_docstr: `Hierarchical Dirichlet Process model <http://jmlr.csail.mit.edu/proceedings/papers/v15/wang11a/wang11a.pdf>`_
  
  Topic models promise to help summarize and organize large archives of texts that cannot be easily analyzed by hand.
  Hierarchical Dirichlet process (HDP) is a powerful mixed-membership model for the unsupervised analysis of grouped
  data. Unlike its finite counterpart, latent Dirichlet allocation, the HDP topic model infers the number of topics
  from the data. Here we have used Online HDP, which provides the speed of online variational Bayes with the modeling
  flexibility of the HDP. The idea behind Online variational Bayes in general is to optimize the variational
  objective function  with stochastic optimization.The challenge we face is that the existing coordinate ascent
  variational Bayes algorithms for the HDP require complicated approximation methods or numerical optimization. This
  model utilises stick breaking construction of Hdp which enables it to allow for coordinate-ascent variational Bayes
  without numerical approximation.
  
  **Stick breaking construction**
  
  To understand the HDP model we need to understand how it is modelled using the stick breaking construction. A very
  good analogy to understand the stick breaking construction is `chinese restaurant franchise
  <https://www.cs.princeton.edu/courses/archive/fall07/cos597C/scribe/20070921.pdf>`_.
  
  
  For this assume that there is a restaurant franchise (`corpus`) which has a large number of restaurants
  (`documents`, `j`) under it. They have a global menu of dishes (`topics`, :math:`\Phi_{k}`) which they serve.
  Also, a single dish (`topic`, :math:`\Phi_{k}`) is only served at a single table `t` for all the customers
  (`words`, :math:`\theta_{j,i}`) who sit at that table.
  So, when a customer enters the restaurant he/she has the choice to make where he/she wants to sit.
  He/she can choose to sit at a table where some customers are already sitting , or he/she can choose to sit
  at a new table. Here the probability of choosing each option is not same.
  
  Now, in this the global menu of dishes correspond to the global atoms  :math:`\Phi_{k}`, and each restaurant
  correspond to a single document `j`. So the number of dishes served in a particular restaurant correspond to the
  number of topics in a particular document. And the number of people sitting at each table correspond to the number
  of words belonging to each topic inside the document `j`.
  
  Now, coming on to the stick breaking construction, the concept understood from the chinese restaurant franchise is
  easily carried over to the stick breaking construction for hdp (`"Figure 1" from "Online Variational Inference
  for the Hierarchical Dirichlet Process" <http://proceedings.mlr.press/v15/wang11a/wang11a.pdf>`_).
  
  A two level hierarchical dirichlet process is a collection of dirichlet processes :math:`G_{j}` , one for each
  group, which share a base distribution :math:`G_{0}`, which is also a dirichlet process. Also, all :math:`G_{j}`
  share the same set of atoms, :math:`\Phi_{k}`, and only the atom weights :math:`\pi _{jt}` differs.
  
  There will be multiple document-level atoms :math:`\psi_{jt}` which map to the same corpus-level atom
  :math:`\Phi_{k}`. Here, the :math:`\beta` signify the weights given to each of the topics globally. Also, each
  factor :math:`\theta_{j,i}` is distributed according to :math:`G_{j}`, i.e., it takes on the value of
  :math:`\Phi_{k}` with probability :math:`\pi _{jt}`. :math:`C_{j,t}` is an indicator variable whose value `k`
  signifies the index of :math:`\Phi`. This helps to map :math:`\psi_{jt}` to :math:`\Phi_{k}`.
  
  The top level (`corpus` level) stick proportions correspond the values of :math:`\beta`,
  bottom level (`document` level) stick proportions correspond to the values of :math:`\pi`.
  The truncation level for the corpus (`K`) and document (`T`) corresponds to the number of :math:`\beta`
  and :math:`\pi` which are in existence.
  
  Now, whenever coordinate ascent updates are to be performed, they happen at two level. The document level as well
  as corpus level.
  
  At document level, we update the following:
  
  #. The parameters to the document level sticks, i.e, a and b parameters of :math:`\beta` distribution of the
     variable :math:`\pi _{jt}`.
  #. The parameters to per word topic indicators, :math:`Z_{j,n}`. Here :math:`Z_{j,n}` selects topic parameter
     :math:`\psi_{jt}`.
  #. The parameters to per document topic indices :math:`\Phi_{jtk}`.
  
  At corpus level, we update the following:
  
  #. The parameters to the top level sticks, i.e., the parameters of the :math:`\beta` distribution for the
     corpus level :math:`\beta`, which signify the topic distribution at corpus level.
  #. The parameters to the topics :math:`\Phi_{k}`.
  
  Now coming on to the steps involved, procedure for online variational inference for the Hdp model is as follows:
  
  1. We initialise the corpus level parameters, topic parameters randomly and set current time to 1.
  2. Fetch a random document j from the corpus.
  3. Compute all the parameters required for document level updates.
  4. Compute natural gradients of corpus level parameters.
  5. Initialise the learning rate as a function of kappa, tau and current time. Also, increment current time by 1
     each time it reaches this step.
  6. Update corpus level parameters.
  
  Repeat 2 to 6 until stopping condition is not met.
  
  Here the stopping condition corresponds to
  
  * time limit expired
  * chunk limit reached
  * whole corpus processed
  
  Attributes
  ----------
  lda_alpha : numpy.ndarray
      Same as :math:`\alpha` from :class:`gensim.models.ldamodel.LdaModel`.
  lda_beta : numpy.ndarray
      Same as :math:`\beta` from from :class:`gensim.models.ldamodel.LdaModel`.
  m_D : int
      Number of documents in the corpus.
  m_Elogbeta : numpy.ndarray:
      Stores value of dirichlet expectation, i.e., compute :math:`E[log \theta]` for a vector
      :math:`\theta \sim Dir(\alpha)`.
  m_lambda : {numpy.ndarray, float}
      Drawn samples from the parameterized gamma distribution.
  m_lambda_sum : {numpy.ndarray, float}
      An array with the same shape as `m_lambda`, with the specified axis (1) removed.
  m_num_docs_processed : int
      Number of documents finished processing.This is incremented in size of chunks.
  m_r : list
      Acts as normaliser in lazy updating of `m_lambda` attribute.
  m_rhot : float
      Assigns weight to the information obtained from the mini-chunk and its value it between 0 and 1.
  m_status_up_to_date : bool
      Flag to indicate whether `lambda `and :math:`E[log \theta]` have been updated if True, otherwise - not.
  m_timestamp : numpy.ndarray
      Helps to keep track and perform lazy updates on lambda.
  m_updatect : int
      Keeps track of current time and is incremented every time :meth:`~gensim.models.hdpmodel.HdpModel.update_lambda`
      is called.
  m_var_sticks : numpy.ndarray
      Array of values for stick.
  m_varphi_ss : numpy.ndarray
      Used to update top level sticks.
  m_W : int
      Length of dictionary for the input corpus.
class_docstr_tok: ["`","Hierarchical","Dirichlet","Process","model","<","http",":","\/\/jmlr.csail.mit.edu\/proceedings\/papers\/v15\/wang11a\/wang11a.pdf",">","`","_","Topic","models","promise","to","help","summarize","and","organize","large","archives","of","texts","that","can","not","be","easily","analyzed","by","hand",".","Hierarchical","Dirichlet","process","(","HDP",")","is","a","powerful","mixed-membership","model","for","the","unsupervised","analysis","of","grouped","data",".","Unlike","its","finite","counterpart",",","latent","Dirichlet","allocation",",","the","HDP","topic","model","infers","the","number","of","topics","from","the","data",".","Here","we","have","used","Online","HDP",",","which","provides","the","speed","of","online","variational","Bayes","with","the","modeling","flexibility","of","the","HDP",".","The","idea","behind","Online","variational","Bayes","in","general","is","to","optimize","the","variational","objective","function","with","stochastic","optimization.The","challenge","we","face","is","that","the","existing","coordinate","ascent","variational","Bayes","algorithms","for","the","HDP","require","complicated","approximation","methods","or","numerical","optimization",".","This","model","utilises","stick","breaking","construction","of","Hdp","which","enables","it","to","allow","for","coordinate-ascent","variational","Bayes","without","numerical","approximation",".","*","*","Stick","breaking","construction","*","*","To","understand","the","HDP","model","we","need","to","understand","how","it","is","modelled","using","the","stick","breaking","construction",".","A","very","good","analogy","to","understand","the","stick","breaking","construction","is","`","chinese","restaurant","franchise","<","https",":","\/\/www.cs.princeton.edu\/courses\/archive\/fall07\/cos597C\/scribe\/20070921.pdf",">","`","_",".","For","this","assume","that","there","is","a","restaurant","franchise","(","`","corpus","`",")","which","has","a","large","number","of","restaurants","(","`","documents","`",",","`","j","`",")","under","it",".","They","have","a","global","menu","of","dishes","(","`","topics","`",",",":","math",":","`","\\Phi_","{","k","}","`",")","which","they","serve",".","Also",",","a","single","dish","(","`","topic","`",",",":","math",":","`","\\Phi_","{","k","}","`",")","is","only","served","at","a","single","table","`","t","`","for","all","the","customers","(","`","words","`",",",":","math",":","`","\\theta_","{","j",",","i","}","`",")","who","sit","at","that","table",".","So",",","when","a","customer","enters","the","restaurant","he\/she","has","the","choice","to","make","where","he\/she","wants","to","sit",".","He\/she","can","choose","to","sit","at","a","table","where","some","customers","are","already","sitting",",","or","he\/she","can","choose","to","sit","at","a","new","table",".","Here","the","probability","of","choosing","each","option","is","not","same",".","Now",",","in","this","the","global","menu","of","dishes","correspond","to","the","global","atoms",":","math",":","`","\\Phi_","{","k","}","`",",","and","each","restaurant","correspond","to","a","single","document","`","j","`",".","So","the","number","of","dishes","served","in","a","particular","restaurant","correspond","to","the","number","of","topics","in","a","particular","document",".","And","the","number","of","people","sitting","at","each","table","correspond","to","the","number","of","words","belonging","to","each","topic","inside","the","document","`","j","`",".","Now",",","coming","on","to","the","stick","breaking","construction",",","the","concept","understood","from","the","chinese","restaurant","franchise","is","easily","carried","over","to","the","stick","breaking","construction","for","hdp","(","`","``","Figure","1","''","from","``","Online","Variational","Inference","for","the","Hierarchical","Dirichlet","Process","''","<","http",":","\/\/proceedings.mlr.press\/v15\/wang11a\/wang11a.pdf",">","`","_",")",".","A","two","level","hierarchical","dirichlet","process","is","a","collection","of","dirichlet","processes",":","math",":","`","G_","{","j","}","`",",","one","for","each","group",",","which","share","a","base","distribution",":","math",":","`","G_","{","0","}","`",",","which","is","also","a","dirichlet","process",".","Also",",","all",":","math",":","`","G_","{","j","}","`","share","the","same","set","of","atoms",",",":","math",":","`","\\Phi_","{","k","}","`",",","and","only","the","atom","weights",":","math",":","`","\\pi","_","{","jt","}","`","differs",".","There","will","be","multiple","document-level","atoms",":","math",":","`","\\psi_","{","jt","}","`","which","map","to","the","same","corpus-level","atom",":","math",":","`","\\Phi_","{","k","}","`",".","Here",",","the",":","math",":","`","\\beta","`","signify","the","weights","given","to","each","of","the","topics","globally",".","Also",",","each","factor",":","math",":","`","\\theta_","{","j",",","i","}","`","is","distributed","according","to",":","math",":","`","G_","{","j","}","`",",","i.e.",",","it","takes","on","the","value","of",":","math",":","`","\\Phi_","{","k","}","`","with","probability",":","math",":","`","\\pi","_","{","jt","}","`",".",":","math",":","`","C_","{","j",",","t","}","`","is","an","indicator","variable","whose","value","`","k","`","signifies","the","index","of",":","math",":","`","\\Phi","`",".","This","helps","to","map",":","math",":","`","\\psi_","{","jt","}","`","to",":","math",":","`","\\Phi_","{","k","}","`",".","The","top","level","(","`","corpus","`","level",")","stick","proportions","correspond","the","values","of",":","math",":","`","\\beta","`",",","bottom","level","(","`","document","`","level",")","stick","proportions","correspond","to","the","values","of",":","math",":","`","\\pi","`",".","The","truncation","level","for","the","corpus","(","`","K","`",")","and","document","(","`","T","`",")","corresponds","to","the","number","of",":","math",":","`","\\beta","`","and",":","math",":","`","\\pi","`","which","are","in","existence",".","Now",",","whenever","coordinate","ascent","updates","are","to","be","performed",",","they","happen","at","two","level",".","The","document","level","as","well","as","corpus","level",".","At","document","level",",","we","update","the","following",":","#",".","The","parameters","to","the","document","level","sticks",",","i.e",",","a","and","b","parameters","of",":","math",":","`","\\beta","`","distribution","of","the","variable",":","math",":","`","\\pi","_","{","jt","}","`",".","#",".","The","parameters","to","per","word","topic","indicators",",",":","math",":","`","Z_","{","j",",","n","}","`",".","Here",":","math",":","`","Z_","{","j",",","n","}","`","selects","topic","parameter",":","math",":","`","\\psi_","{","jt","}","`",".","#",".","The","parameters","to","per","document","topic","indices",":","math",":","`","\\Phi_","{","jtk","}","`",".","At","corpus","level",",","we","update","the","following",":","#",".","The","parameters","to","the","top","level","sticks",",","i.e.",",","the","parameters","of","the",":","math",":","`","\\beta","`","distribution","for","the","corpus","level",":","math",":","`","\\beta","`",",","which","signify","the","topic","distribution","at","corpus","level",".","#",".","The","parameters","to","the","topics",":","math",":","`","\\Phi_","{","k","}","`",".","Now","coming","on","to","the","steps","involved",",","procedure","for","online","variational","inference","for","the","Hdp","model","is","as","follows",":","1",".","We","initialise","the","corpus","level","parameters",",","topic","parameters","randomly","and","set","current","time","to","1",".","2",".","Fetch","a","random","document","j","from","the","corpus",".","3",".","Compute","all","the","parameters","required","for","document","level","updates",".","4",".","Compute","natural","gradients","of","corpus","level","parameters",".","5",".","Initialise","the","learning","rate","as","a","function","of","kappa",",","tau","and","current","time",".","Also",",","increment","current","time","by","1","each","time","it","reaches","this","step",".","6",".","Update","corpus","level","parameters",".","Repeat","2","to","6","until","stopping","condition","is","not","met",".","Here","the","stopping","condition","corresponds","to","*","time","limit","expired","*","chunk","limit","reached","*","whole","corpus","processed","Attributes","--","--","--","--","--","lda_alpha",":","numpy.ndarray","Same","as",":","math",":","`","\\alpha","`","from",":","class",":","`","gensim.models.ldamodel.LdaModel","`",".","lda_beta",":","numpy.ndarray","Same","as",":","math",":","`","\\beta","`","from","from",":","class",":","`","gensim.models.ldamodel.LdaModel","`",".","m_D",":","int","Number","of","documents","in","the","corpus",".","m_Elogbeta",":","numpy.ndarray",":","Stores","value","of","dirichlet","expectation",",","i.e.",",","compute",":","math",":","`","E","[","log","\\theta","]","`","for","a","vector",":","math",":","`","\\theta","\\sim","Dir","(","\\alpha",")","`",".","m_lambda",":","{","numpy.ndarray",",","float","}","Drawn","samples","from","the","parameterized","gamma","distribution",".","m_lambda_sum",":","{","numpy.ndarray",",","float","}","An","array","with","the","same","shape","as","`","m_lambda","`",",","with","the","specified","axis","(","1",")","removed",".","m_num_docs_processed",":","int","Number","of","documents","finished","processing.This","is","incremented","in","size","of","chunks",".","m_r",":","list","Acts","as","normaliser","in","lazy","updating","of","`","m_lambda","`","attribute",".","m_rhot",":","float","Assigns","weight","to","the","information","obtained","from","the","mini-chunk","and","its","value","it","between","0","and","1.","m_status_up_to_date",":","bool","Flag","to","indicate","whether","`","lambda","`","and",":","math",":","`","E","[","log","\\theta","]","`","have","been","updated","if","True",",","otherwise","-","not",".","m_timestamp",":","numpy.ndarray","Helps","to","keep","track","and","perform","lazy","updates","on","lambda",".","m_updatect",":","int","Keeps","track","of","current","time","and","is","incremented","every","time",":","meth",":","`","~gensim.models.hdpmodel.HdpModel.update_lambda","`","is","called",".","m_var_sticks",":","numpy.ndarray","Array","of","values","for","stick",".","m_varphi_ss",":","numpy.ndarray","Used","to","update","top","level","sticks",".","m_W",":","int","Length","of","dictionary","for","the","input","corpus","."]
docstr: Get a trained ldamodel object which is closest to the current hdp model.
  
  The `num_topics=m_T`, so as to preserve the matrices shapes when we assign alpha and beta.
  
  Returns
  -------
  :class:`~gensim.models.ldamodel.LdaModel`
      Closest corresponding LdaModel to current HdpModel.
code: def suggested_lda_model(self):
      """Get a trained ldamodel object which is closest to the current hdp model.
  
      The `num_topics=m_T`, so as to preserve the matrices shapes when we assign alpha and beta.
  
      Returns
      -------
      :class:`~gensim.models.ldamodel.LdaModel`
          Closest corresponding LdaModel to current HdpModel.
  
      """
      alpha, beta = self.hdp_to_lda()
      ldam = ldamodel.LdaModel(
          num_topics=self.m_T,
          alpha=alpha,
          id2word=self.id2word,
          random_state=self.random_state,
          dtype=np.float64,
      )
      ldam.expElogbeta[:] = beta
      return ldam
  
imports: import logging
  import time
  import warnings
  import numpy
  from scipy.special import gammaln, psi
  from gensim import interfaces, utils, matutils
  from gensim.matutils import dirichlet_expectation, mean_absolute_difference
  from gensim.models import basemodel, ldamodel
  from gensim.utils import deprecated
label_desc: Use image node_id 17 for calling the HdpModel obj's underlying member method code with example usage: obj.suggested_lda_model() and returns: ldam