def test_naive_case_2(self): # 2 # | # 0 - 4 3 # | # 1 points = [(0,0), (0,-1), (6,1), (6,0), (1,0)] matrix = CondensedMatrix(pdist(points)) s_algo = SpectralClusteringAlgorithm(matrix, max_clusters = 2, sigma_sq = 0.5, use_k_medoids = False, verbose = True) clusters = s_algo.perform_clustering({"k":2}).clusters for c in clusters: self.assertIn(c.all_elements, [[0,1,4],[2,3]])
def test_naive_case_1(self): # 1 5 8 # | | | # 0 - 3 4 6 - 7 # | | # 2 9 points = [(0, 0), (0, 1), (0, -1), (1, 0), (3, 0), (3, 1), (6, 0), (7, 0), (7, 1), (7, -1)] matrix = CondensedMatrix(pdist(points)) s_algo = SpectralClusteringAlgorithm(matrix, sigma=20, max_clusters=3, use_k_medoids=False, verbose=True) clusters = s_algo.perform_clustering({"k": 3}).clusters # sometimes works, sometimes not (due to kmeans/medoids unstabilities) for c in clusters: self.assertIn(c.all_elements, [[0, 1, 2, 3], [6, 7, 8, 9], [4, 5]])
def test_naive_case_1(self): # 1 5 8 # | | | # 0 - 3 4 6 - 7 # | | # 2 9 points = [(0,0),(0,1),(0,-1),(1,0), (3,0),(3,1), (6,0),(7,0),(7,1),(7,-1)] matrix = CondensedMatrix(pdist(points)) s_algo = SpectralClusteringAlgorithm(matrix, sigma = 20, max_clusters = 3, use_k_medoids = False, verbose = True) clusters = s_algo.perform_clustering({"k":3}).clusters # sometimes works, sometimes not (due to kmeans/medoids unstabilities) for c in clusters: self.assertIn(c.all_elements, [[0, 1, 2, 3],[6, 7, 8, 9],[4, 5]])
Created on 14/01/2013 @author: victor ''' import numpy import time from pyRMSD.condensedMatrix import CondensedMatrix from pyproct.algorithms.spectral.spectralClusteringAlgorithm import SpectralClusteringAlgorithm if __name__ == '__main__': MAX_ELEMENTS = 2000 DATA_LEN = (MAX_ELEMENTS * (MAX_ELEMENTS-1))/2 numpy_matrix_data = numpy.abs(numpy.random.rand(DATA_LEN)) matrix = CondensedMatrix(numpy_matrix_data) W = SpectralClusteringAlgorithm.calculate_adjacency_matrix(matrix,1) W_tmp = numpy.array(W) t1 = time.time() L_PYTHON = SpectralClusteringAlgorithm.calculate_laplacian(W_tmp, matrix, "PYTHON")[0] t2 = time.time() print 'Calculations took %0.3f s' % (t2-t1) W_tmp = numpy.array(W) t1 = time.time() L_NUMPY = SpectralClusteringAlgorithm.calculate_laplacian(W_tmp, matrix, "NUMPY")[0] t2 = time.time() print 'Calculations took %0.3f s' % (t2-t1) W_tmp = numpy.array(W) t1 = time.time()
Created on 14/01/2013 @author: victor """ import numpy import time from pyRMSD.condensedMatrix import CondensedMatrix from pyproct.algorithms.spectral.spectralClusteringAlgorithm import SpectralClusteringAlgorithm if __name__ == '__main__': MAX_ELEMENTS = 2000 DATA_LEN = (MAX_ELEMENTS * (MAX_ELEMENTS-1))/2 numpy_matrix_data = numpy.abs(numpy.random.rand(DATA_LEN)) matrix = CondensedMatrix(numpy_matrix_data) W = SpectralClusteringAlgorithm.calculate_adjacency_matrix(matrix,1) W_tmp = numpy.array(W) t1 = time.time() L_PYTHON = SpectralClusteringAlgorithm.calculate_laplacian(W_tmp, matrix, "PYTHON")[0] t2 = time.time() print 'Calculations took %0.3f s' % (t2-t1) W_tmp = numpy.array(W) t1 = time.time() L_NUMPY = SpectralClusteringAlgorithm.calculate_laplacian(W_tmp, matrix, "NUMPY")[0] t2 = time.time() print 'Calculations took %0.3f s' % (t2-t1) W_tmp = numpy.array(W) t1 = time.time()