Exemplo n.º 1
0
 def __crand(self, keep_simulations):
     y = self.y
     if keep_simulations:
         rGs = np.zeros((self.n, self.permutations))
     larger = np.zeros((self.n,))
     n_1 = self.n - 1
     rid = list(range(n_1))
     prange = list(range(self.permutations))
     k = self.w.max_neighbors + 1
     rids = np.array([np.random.permutation(rid)[0:k] for i in prange])
     ids = np.arange(self.w.n)
     ido = self.w.id_order
     wc = self.__getCardinalities()
     if self.w_transform == "r":
         den = np.array(wc) + self.star
     else:
         den = np.ones(self.w.n)
     for i in range(self.w.n):
         idsi = ids[ids != i]
         np.random.shuffle(idsi)
         yi_star = y[i] * self.star
         wci = wc[i]
         rGs_i = (y[idsi[rids[:, 0:wci]]]).sum(1) + yi_star
         rGs_i = (np.array(rGs_i) / den[i]) / (self.y_sum - (1 - self.star) * y[i])
         if keep_simulations:
             rGs[i] = rGs_i
         larger[i] = (rGs_i >= self.Gs[i]).sum()
     if keep_simulations:
         self.rGs = rGs
     below = (self.permutations - larger) < larger
     larger[below] = self.permutations - larger[below]
     self.p_sim = (larger + 1) / (self.permutations + 1)
Exemplo n.º 2
0
 def __crand(self):
     y = self.y
     rGs = np.zeros((self.n, self.permutations))
     n_1 = self.n - 1
     rid = list(range(n_1))
     prange = list(range(self.permutations))
     k = self.w.max_neighbors + 1
     rids = np.array([np.random.permutation(rid)[0:k] for i in prange])
     ids = np.arange(self.w.n)
     ido = self.w.id_order
     wc = self.__getCardinalities()
     if self.w_transform == "r":
         den = np.array(wc) + self.star
     else:
         den = np.ones(self.w.n)
     for i in range(self.w.n):
         idsi = ids[ids != i]
         np.random.shuffle(idsi)
         yi_star = y[i] * self.star
         wci = wc[i]
         rGs[i] = (y[idsi[rids[:, 0:wci]]]).sum(1) + yi_star
         rGs[i] = (np.array(rGs[i]) / den[i]) / (self.y_sum - (1 - self.star) * y[i])
     self.rGs = rGs