Esempio n. 1
0
    def _get_statistics(self,data):
        # NOTE: this is a stochastic function: it samples auxiliary variables
        counts = np.array(data,ndmin=2,order='C')

        # sample m's, which sample an inverse of the weak limit projection
        if counts.sum() == 0:
            return 0, 0
        else:
            m = sample_crp_tablecounts(self.concentration,counts,self.weighted_cols)
            return counts.sum(1), m.sum()
Esempio n. 2
0
    def _get_statistics(self,data):
        # NOTE: this is a stochastic function: it samples auxiliary variables
        counts = np.array(data,ndmin=2,order='C')

        # sample m's, which sample an inverse of the weak limit projection
        if counts.sum() == 0:
            return 0, 0
        else:
            m = sample_crp_tablecounts(self.concentration,counts,self.weighted_cols)
            return counts.sum(1), m.sum()
Esempio n. 3
0
 def resample(self,data=[],niter=20):
     if getdatasize(data) == 0:
         self.p = np.random.beta(self.alpha_0,self.beta_0)
         self.r = np.random.gamma(self.k_0,self.theta_0)
     else:
         data = atleast_2d(flattendata(data))
         N = len(data)
         for itr in range(niter):
             ### resample r
             msum = sample_crp_tablecounts(self.r,data).sum()
             self.r = np.random.gamma(self.k_0 + msum, 1/(1/self.theta_0 - N*np.log(1-self.p)))
             ### resample p
             self.p = np.random.beta(self.alpha_0 + data.sum(), self.beta_0 + N*self.r)
     return self
Esempio n. 4
0
 def resample(self,data=[],niter=20):
     if getdatasize(data) == 0:
         self.p = np.random.beta(self.alpha_0,self.beta_0)
         self.r = np.random.gamma(self.k_0,self.theta_0)
     else:
         data = np.atleast_2d(flattendata(data))
         ones = np.ones(data.shape[1],dtype=float)
         for itr in range(niter):
             ### resample r
             msum = sample_crp_tablecounts(float(self.r),data,ones).sum()
             self.r = np.random.gamma(self.k_0 + msum, 1/(1/self.theta_0 - N*np.log(1-self.p)))
             ### resample p
             self.p = np.random.beta(self.alpha_0 + data.sum(), self.beta_0 + N*self.r)
     return self