class_docstr: Encapsulate the inner State Space Language Model for DTM.
  
  Some important attributes of this class:
  
      * `obs` is a matrix containing the document to topic ratios.
      * `e_log_prob` is a matrix containing the topic to word ratios.
      * `mean` contains the mean values to be used for inference for each word for a time slice.
      * `variance` contains the variance values to be used for inference of word in a time slice.
      * `fwd_mean` and`fwd_variance` are the forward posterior values for the mean and the variance.
      * `zeta` is an extra variational parameter with a value for each time slice.
class_docstr_tok: ["Encapsulate","the","inner","State","Space","Language","Model","for","DTM",".","Some","important","attributes","of","this","class",":","*","`","obs","`","is","a","matrix","containing","the","document","to","topic","ratios",".","*","`","e_log_prob","`","is","a","matrix","containing","the","topic","to","word","ratios",".","*","`","mean","`","contains","the","mean","values","to","be","used","for","inference","for","each","word","for","a","time","slice",".","*","`","variance","`","contains","the","variance","values","to","be","used","for","inference","of","word","in","a","time","slice",".","*","`","fwd_mean","`","and","`","fwd_variance","`","are","the","forward","posterior","values","for","the","mean","and","the","variance",".","*","`","zeta","`","is","an","extra","variational","parameter","with","a","value","for","each","time","slice","."]
docstr: Get the mean, based on the `Variational Kalman Filtering approach for Approximate Inference (section 3.1)
  <https://mimno.infosci.cornell.edu/info6150/readings/dynamic_topic_models.pdf>`_.
  
  Notes
  -----
  This function essentially computes E[eta_{t,w}] for t = 1:T.
  
  .. :math::
  
      Fwd_Mean(t) ≡  E(beta_{t,w} | beta_ˆ 1:t )
      = (obs_variance / fwd_variance[t - 1] + chain_variance + obs_variance ) * fwd_mean[t - 1] +
      (1 - (obs_variance / fwd_variance[t - 1] + chain_variance + obs_variance)) * beta
  
  .. :math::
  
      Mean(t) ≡ E(beta_{t,w} | beta_ˆ 1:T )
      = fwd_mean[t - 1] + (obs_variance / fwd_variance[t - 1] + obs_variance) +
      (1 - obs_variance / fwd_variance[t - 1] + obs_variance)) * mean[t]
  
  Parameters
  ----------
  word: int
      The word's ID.
  chain_variance : float
      Gaussian parameter defined in the beta distribution to dictate how the beta values evolve over time.
  
  Returns
  -------
  (numpy.ndarray, numpy.ndarray)
      The first returned value is the mean of each word in each time slice, the second value is the
      inferred posterior mean for the same pairs.
docstr_tok: ["Get","the","mean",",","based","on","the","`","Variational","Kalman","Filtering","approach","for","Approximate","Inference","(","section","3.1",")","<","https",":","\/\/mimno.infosci.cornell.edu\/info6150\/readings\/dynamic_topic_models.pdf",">","`","_",".","Notes","--","--","-","This","function","essentially","computes","E","[","\beta_","{","t",",","w","}","]","for","t","=","1",":","T.","..",":","math",":",":","Fwd_Mean","(","t",")","\u2261","E","(","beta_","{","t",",","w","}","|","beta_\u02c6","1",":","t",")","=","(","obs_variance","\/","fwd_variance","[","t","-","1","]","+","chain_variance","+","obs_variance",")","*","fwd_mean","[","t","-","1","]","+","(","1","-","(","obs_variance","\/","fwd_variance","[","t","-","1","]","+","chain_variance","+","obs_variance",")",")","*","beta","..",":","math",":",":","Mean","(","t",")","\u2261","E","(","beta_","{","t",",","w","}","|","beta_\u02c6","1",":","T",")","=","fwd_mean","[","t","-","1","]","+","(","obs_variance","\/","fwd_variance","[","t","-","1","]","+","obs_variance",")","+","(","1","-","obs_variance","\/","fwd_variance","[","t","-","1","]","+","obs_variance",")",")","*","mean","[","t","]","Parameters","--","--","--","--","--","word",":","int","The","word","'s","ID",".","chain_variance",":","float","Gaussian","parameter","defined","in","the","beta","distribution","to","dictate","how","the","beta","values","evolve","over","time",".","Returns","--","--","--","-","(","numpy.ndarray",",","numpy.ndarray",")","The","first","returned","value","is","the","mean","of","each","word","in","each","time","slice",",","the","second","value","is","the","inferred","posterior","mean","for","the","same","pairs","."]
code: def compute_post_mean(self, word, chain_variance):
      """Get the mean, based on the `Variational Kalman Filtering approach for Approximate Inference (section 3.1)
      <https://mimno.infosci.cornell.edu/info6150/readings/dynamic_topic_models.pdf>`_.
  
      Notes
      -----
      This function essentially computes E[\beta_{t,w}] for t = 1:T.
  
      .. :math::
  
          Fwd_Mean(t) ≡  E(beta_{t,w} | beta_ˆ 1:t )
          = (obs_variance / fwd_variance[t - 1] + chain_variance + obs_variance ) * fwd_mean[t - 1] +
          (1 - (obs_variance / fwd_variance[t - 1] + chain_variance + obs_variance)) * beta
  
      .. :math::
  
          Mean(t) ≡ E(beta_{t,w} | beta_ˆ 1:T )
          = fwd_mean[t - 1] + (obs_variance / fwd_variance[t - 1] + obs_variance) +
          (1 - obs_variance / fwd_variance[t - 1] + obs_variance)) * mean[t]
  
      Parameters
      ----------
      word: int
          The word's ID.
      chain_variance : float
          Gaussian parameter defined in the beta distribution to dictate how the beta values evolve over time.
  
      Returns
      -------
      (numpy.ndarray, numpy.ndarray)
          The first returned value is the mean of each word in each time slice, the second value is the
          inferred posterior mean for the same pairs.
  
      """
      T = self.num_time_slices
      obs = self.obs[word]
      fwd_variance = self.fwd_variance[word]
      mean = self.mean[word]
      fwd_mean = self.fwd_mean[word]
  
      # forward
      fwd_mean[0] = 0
      for t in range(1, T + 1):
          c = self.obs_variance / (
              fwd_variance[t - 1] + chain_variance + self.obs_variance
          )
          fwd_mean[t] = c * fwd_mean[t - 1] + (1 - c) * obs[t - 1]
  
      # backward pass
      mean[T] = fwd_mean[T]
      for t in range(T - 1, -1, -1):
          if chain_variance == 0.0:
              c = 0.0
          else:
              c = chain_variance / (fwd_variance[t] + chain_variance)
          mean[t] = c * fwd_mean[t] + (1 - c) * mean[t + 1]
      return mean, fwd_mean
  
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 4 for calling the sslm obj's underlying member method code with example usage: obj.compute_post_mean(word, chain_variance) and returns: mean,  fwd_mean