Exemple #1
0
 def shuffle_sets(self, samples, targets):
     rng_state = np.random.get_state()
     copy_samples = np.empty((np.shape(samples)))
     copy_samples[:] = samples
     np.random.shuffle(copy_samples)
     np.random.set_state(rng_state)
     copy_targets = np.empty((np.shape(targets)))
     copy_targets[:] = targets
     np.random.shuffle(copy_targets)
     return copy_samples[:self.SAMPLES,:], copy_targets[:self.SAMPLES,:]
Exemple #2
0
def cpd_G(x, y, beta):
    '''
    Constructs gaussian affinity matrix
    :param x: goal positions
    :param y: current positions
    :param beta: std of G
    :return: Gaussian affinity matrix G
    '''
    k = -2 * beta**2
    [n, d] = cp.shape(x)
    [m, d] = cp.shape(y)

    G = cp.tile(x, [m, 1, 1]) - cp.reshape(
        cp.repeat(y[:, :, cp.newaxis], n, axis=0), [m, n, d])
    G = cp.sum(cp.power(G, 2), 2)
    G = G / k

    return cp.exp(G)
 def __pca(self, XMat, k):
     average = np.mean(XMat, axis=0)
     m, n = np.shape(XMat)  # m: samples_nums, n: features
     data_adjust = XMat - average
     cov_x = self.__cov(data_adjust.T)  # 计算协方差矩阵
     feat_value, feat_vec = npy.linalg.eig(cov_x.get())  # 求解协方差矩阵的特征值和特征向量
     index = np.argsort(-feat_value)  # 依照featValue进行从大到小排序
     if k > n:
         print("k must lower than feature number")
         return
     else:
         selectVec = feat_vec[:, index[:k]]  # 所以这里须要进行转置
         finalData = np.matmul(data_adjust, np.asarray(selectVec))  # cupy
     return finalData, np.asarray(selectVec)
 def _truncnorm_ppf(self,q, N):
     out = cp.zeros(cp.shape(q))
     delta = self._truncnorm_get_delta(N)
     cond1 = delta > 0
     cond2 = (delta > 0) & (self.a > 0)
     cond21 = (delta > 0) & (self.a<=0)
     if cp.any(cond1) == True:
         sa = self.norm_sf(a[cond2])
         out[:,cond2] = -self.ndtri((1 - q[:,cond2]) * sa)
     if cp.any(cond21) == True:
         na = norm_cdf(self.a[cond21])
         out[:,cond21] = self._ndtri(q[:,cond21]  + na * (1.0 - q[:,cond21]))
     cond3 = ~cond1 & cp.isinf(self.b)
     cond4 = ~cond1 & cp.isinf(self.a)
     if cp.any(cond3) == True:
         out[:,cond3] = -self._norm_ilogcdf(cp.log1p(-q[:,cond3]) + self.norm_logsf(self.a[cond3]))
     if cp.any(cond4) == True:
         out[:,cond4] = self._norm_ilogcdf(cp.log(q) + self.norm_logcdf(self.b))
     cond5 = out < self.a
     if cp.any(cond5) == True:
         out[cond5] = ((cond5) * self.a)[cond5]
     return out
Exemple #5
0
 def test_shape_list(self):
     shape = self.shape
     a = testing.shaped_arange(shape, numpy)
     a = a.tolist()
     assert cupy.shape(a) == shape
Exemple #6
0
 def test_shape(self):
     shape = self.shape
     for xp in (numpy, cupy):
         a = testing.shaped_arange(shape, xp)
         assert cupy.shape(a) == shape