Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pairwise_distance_matrix():
"""Test pairwise distance"""
A = np.array([2*np.eye(3), 3*np.eye(3)])
B = np.array([2*np.eye(3), 3*np.eye(3)])
pairwise_distance(A, B)
def _score_ttest(self, X, y):
"""Get the score"""
mdm = self.mdm.fit(X, y)
covmeans = numpy.array(mdm.covmeans_)
# estimates distances between means
n_classes = len(covmeans)
pairs = pairwise_distance(covmeans, metric=mdm.metric_dist)
mean_dist = numpy.triu(pairs).sum()
mean_dist /= (n_classes * (n_classes - 1)) / 2.0
dist = 0
for ix, classe in enumerate(mdm.classes_):
di = (distance(
X[y == classe], covmeans[ix], metric=mdm.metric_dist)
**2).mean()
dist += (di / numpy.sum(y == classe))
score = mean_dist / numpy.sqrt(dist)
return score
def _get_affinity_matrix(self, X, eps):
# make matrix with pairwise distances between points
distmatrix = pairwise_distance(X, metric=self.metric)
# determine which scale for the gaussian kernel
if self.eps is None:
eps = np.median(distmatrix)**2 / 2
# make kernel matrix from the distance matrix
kernel = np.exp(-distmatrix**2 / (4 * eps))
# normalize the kernel matrix
q = np.dot(kernel, np.ones(len(kernel)))
kernel_n = np.divide(kernel, np.outer(q, q))
return kernel_n
def __init_transform(self, X):
"""Init tr"""
self.mdm = MDM(metric=self.metric, n_jobs=self.n_jobs)
if self.mode == 'ftest':
self.global_mean = mean_covariance(X, metric=self.mdm.metric_mean)
elif self.mode == 'pairwise':
X = pairwise_distance(X, metric=self.mdm.metric_dist)**2
return X