def get_S(self, dimensions=2, pub=None): similarity = self.get_similarity(self.statistic) if pub is not None: pub.array_as_image('similarity', similarity, caption='Similarity statistic') plot_spectrum(pub, 'similarity', similarity) if self.scale_score: R = scale_score(similarity).astype('float32') R = R / R.max() if pub is not None: pub.array_as_image('scale_score', R) else: R = similarity D = 1 - R D = D * np.pi / D.max() np.fill_diagonal(D, 0) if pub is not None: # pub.array_as_image('D', D) P = D * D B = double_center(P) # plot_spectrum(pub, 'D', D) # plot_spectrum(pub, 'P', P) plot_spectrum(pub, 'B', B) S = mds(D, ndim=dimensions) # S = inner_product_embedding(similarity, 3) # S = S[1:3, :] return S
def rank_test(): ''' Check that the double-centered matrix has small rank. ''' for n in range(5, 50, 5): for k in range(1, 5): P = np.random.rand(k, n) D = euclidean_distances(P) B = double_center(D * D) w, v = eigh(B) #@UnusedVariable w = w[::-1] # descending # normalize wn = w / w[0] small = np.abs(wn[k]) assert_allclose(0, small, atol=1e-7)