Пример #1
0
    def set_global_params(self,
                          K=0,
                          beta=None,
                          U1=None,
                          U0=None,
                          Ebeta=None,
                          EbetaLeftover=None,
                          **kwargs):
        ''' Directly set global parameter vector v
          using provided arguments
    '''
        self.K = K
        if U1 is not None and U0 is not None:
            self.v = U1 / (U1 + U0)

        if Ebeta is not None and EbetaLeftover is not None:
            Ebeta = np.squeeze(Ebeta)
            EbetaLeftover = np.squeeze(EbetaLeftover)
            beta = np.hstack([Ebeta, EbetaLeftover])
        elif beta is not None:
            assert beta.size == K
            beta = np.hstack([beta, np.min(beta) / 100.])
            beta = beta / np.sum(beta)
        if beta is not None:
            assert abs(np.sum(beta) - 1.0) < 0.005
            self.v = OptimPE.beta2v(beta)
        assert self.v.size == self.K
        self.set_helper_params()
Пример #2
0
 def update_global_params_VB(self, SS, **kwargs):
   ''' Update global parameters v that control topic probabilities beta
   '''
   self.K = SS.K
   sumLogPi = np.hstack([SS.sumLogPiActive, SS.sumLogPiUnused])
   assert sumLogPi.size == self.K + 1
   
   try:
     v, fofv, Info = OptimPE.estimate_v(alpha0=self.alpha0, gamma=self.gamma,
                           sumLogPi=sumLogPi, nDoc=SS.nDoc)
     self.v = v
   except ValueError as v:
     if str(v).count('failed') > 0:
       if self.v.size != self.K:
         beta = np.hstack([SS.N, 0.01])
         beta /= beta.sum()
         self.v = OptimPE.beta2v(beta)
       else:
         pass # keep current estimate of v!
   assert self.v.size == self.K
   self.set_helper_params()
Пример #3
0
    def update_global_params_VB(self, SS, **kwargs):
        ''' Update global parameters v that control topic probabilities beta
    '''
        self.K = SS.K
        sumLogPi = np.hstack([SS.sumLogPiActive, SS.sumLogPiUnused])
        assert sumLogPi.size == self.K + 1

        try:
            v, fofv, Info = OptimPE.estimate_v(alpha0=self.alpha0,
                                               gamma=self.gamma,
                                               sumLogPi=sumLogPi,
                                               nDoc=SS.nDoc)
            self.v = v
        except ValueError as v:
            if str(v).count('failed') > 0:
                if self.v.size != self.K:
                    beta = np.hstack([SS.N, 0.01])
                    beta /= beta.sum()
                    self.v = OptimPE.beta2v(beta)
                else:
                    pass  # keep current estimate of v!
        assert self.v.size == self.K
        self.set_helper_params()
Пример #4
0
 def set_global_params(self, K=0, beta=None, U1=None, U0=None, 
                               Ebeta=None, EbetaLeftover=None, **kwargs):
   ''' Directly set global parameter vector v
         using provided arguments
   '''
   self.K = K
   if U1 is not None and U0 is not None:
     self.v = U1 / (U1 + U0)
   
   if Ebeta is not None and EbetaLeftover is not None:
     Ebeta = np.squeeze(Ebeta)
     EbetaLeftover = np.squeeze(EbetaLeftover)
     beta = np.hstack( [Ebeta, EbetaLeftover])
   elif beta is not None:
     assert beta.size == K
     beta = np.hstack([beta, np.min(beta)/100.])
     beta = beta/np.sum(beta)
   if beta is not None:
     assert abs(np.sum(beta) - 1.0) < 0.005
     self.v = OptimPE.beta2v(beta)
   assert self.v.size == self.K
   self.set_helper_params()
Пример #5
0
 def set_helper_params(self):
     self.Ebeta = OptimPE.v2beta(self.v)
Пример #6
0
 def set_helper_params(self):
   self.Ebeta = OptimPE.v2beta(self.v)