示例#1
0
 def sample_theta(self):
   self.theta_hist.append(deepcopy(self.theta))
   
   for label in xrange(self.n_labels):
     dirichlet_params = util.v_sum([self.gamma_theta] * self.N, self.c_word_label[label])
     self.theta[label] = util.sample_dirichlet(dirichlet_params)
     if self.debug:
       print 'Dir-params:', dirichlet_params
       print 'theta:', self.theta[label]
示例#2
0
 def compute_average_theta(self,n_iter=None):
   self.avg_theta = [None] * self.n_labels
   norm = 0
   for theta in self.theta_hist[self.burn_in:n_iter:self.lag]:
     norm += 1
     for topic, probs in enumerate(theta):
       if topic not in self.avg_theta:
         self.avg_theta[topic] = probs
       else:
         self.avg_theta[topic] = util.v_sum(self.avg_theta[topic], probs)
   
   for probs in self.avg_theta:
     #self.avg_theta[topic] = [x/float(norm) for x in self.avg_theta[topic]]
     util.normalize(probs)