Esempio n. 1
0
def npLogPDFDirichlet(mu, params):
    mu = np.array(mu)
    params = np.array(params)
    assert (len(mu) == len(params))
    assert (bd.ispv(mu))
    logPstr = np.sum((params - 1) * np.log(mu))
    logZ = np.sum(log(vgamma(params))) - logGamma(np.sum(params))
    return logPstr - logZ
Esempio n. 2
0
 def append(self, theta):
     assert(bd.ispv(theta))
     if not(self.__pointer in range(self.__record.shape[1])):
         self.__record = np.concatenate([self.__record, np.zeros((self.__record.shape[0], self.__allocUnit))], axis=1)
         self.__counter= np.concatenate([self.__counter,np.zeros(self.__allocUnit)])
     self.__record[:,self.__pointer] = theta
     self.__counter[self.__pointer] = 1.0
     self.__pointer += 1
Esempio n. 3
0
 def pdf(self, mu):
     """Probability Density Function"""
     mu = np.array(mu)
     assert(len(mu)==self.dim())
     assert(bd.ispv(mu))
     pstr = np.product(mu**(self.__params-1))
     Z = np.product(vgamma(self.__params))/math.gamma(np.sum(self.__params))
     return pstr/Z
Esempio n. 4
0
def npLogPDFDirichlet(mu, params):
    mu = np.array(mu)
    params = np.array(params)
    assert(len(mu)==len(params))
    assert(bd.ispv(mu))
    logPstr = np.sum((params-1)*np.log(mu))
    logZ = np.sum(log(vgamma(params))) - logGamma(np.sum(params))
    return logPstr - logZ
Esempio n. 5
0
 def pdf(self, mu):
     """Probability Density Function"""
     mu = np.array(mu)
     assert (len(mu) == self.dim())
     assert (bd.ispv(mu))
     pstr = np.product(mu**(self.__params - 1))
     Z = np.product(vgamma(self.__params)) / math.gamma(
         np.sum(self.__params))
     return pstr / Z
Esempio n. 6
0
 def posterior(self, sample):
     """
     computes the posterior of DP
     sample: index of the observed word for topic learning
     """
     posterior=np.zeros(self.noClusters()+1)
     posterior[:-1] = self.__lfs.compute(sample) * self.__lfs.counter()
     posterior[-1] = self.alpha * self.baseDist.Zpost(sample)
     posterior = posterior/np.sum(posterior)
     assert(bd.ispv(posterior))
     return posterior
Esempio n. 7
0
 def append(self, theta):
     assert (bd.ispv(theta))
     if not (self.__pointer in range(self.__record.shape[1])):
         self.__record = np.concatenate([
             self.__record,
             np.zeros((self.__record.shape[0], self.__allocUnit))
         ],
                                        axis=1)
         self.__counter = np.concatenate(
             [self.__counter,
              np.zeros(self.__allocUnit)])
     self.__record[:, self.__pointer] = theta
     self.__counter[self.__pointer] = 1.0
     self.__pointer += 1