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
def rvs(self,size=[]): return np.concatenate( [atleast_2d(distn.rvs(size=size)) for distn in self._distns],axis=-1)