Esempio n. 1
0
    def templateClusterAllocationOneDimensionData(ccore_flag):
        input_data = [ [random()] for i in range(10) ] + [ [random() + 3] for i in range(10) ] + [ [random() + 5] for i in range(10) ] + [ [random() + 8] for i in range(10) ];

        somsc_instance = somsc(input_data, 4, 100, ccore_flag);
        somsc_instance.process();
        clusters = somsc_instance.get_clusters();

        assert len(clusters) == 4;
        for cluster in clusters:
            assert len(cluster) == 10;
Esempio n. 2
0
    def templateClusterAllocationOneDimensionData(self, ccore_flag):
        input_data = [[random()] for i in range(10)] + [[random() + 3] for i in range(10)] + \
                     [[random() + 5] for i in range(10)] + [[random() + 8] for i in range(10)]

        somsc_instance = somsc(input_data, 4, 100, ccore_flag)
        somsc_instance.process()
        clusters = somsc_instance.get_clusters()

        self.assertEqual(len(clusters), 4)
        for cluster in clusters:
            self.assertEqual(len(cluster), 10)
Esempio n. 3
0
    def predict(self, path_to_file, amount_clusters, points,
                expected_closest_clusters, ccore):
        sample = read_sample(path_to_file)

        somsc_instance = somsc(sample, amount_clusters, 100, ccore)
        somsc_instance.process()

        closest_clusters = somsc_instance.predict(points)
        self.assertEqual(len(expected_closest_clusters), len(closest_clusters))
        self.assertTrue(
            numpy.array_equal(numpy.array(expected_closest_clusters),
                              closest_clusters))
Esempio n. 4
0
def template_clustering(path, amount_clusters, epouch=100, ccore=True):
    sample = read_sample(path)

    somsc_instance = somsc(sample, amount_clusters, epouch, ccore)
    (ticks, _) = timedcall(somsc_instance.process)

    clusters = somsc_instance.get_clusters()

    print("Sample: ", path, "\t\tExecution time: ", ticks, "\n")

    visualizer = cluster_visualizer()
    visualizer.append_clusters(clusters, sample)
    visualizer.show()
Esempio n. 5
0
    def templateLengthProcessData(self, path_to_file, amount_clusters,
                                  expected_cluster_length, ccore):
        sample = read_sample(path_to_file)

        somsc_instance = somsc(sample, amount_clusters, 100, ccore)
        somsc_instance.process()

        clusters = somsc_instance.get_clusters()

        obtained_cluster_sizes = [len(cluster) for cluster in clusters]
        self.assertEqual(len(sample), sum(obtained_cluster_sizes))

        if expected_cluster_length is not None:
            obtained_cluster_sizes.sort()
            expected_cluster_length.sort()
            self.assertEqual(obtained_cluster_sizes, expected_cluster_length)
Esempio n. 6
0
    def templateLengthProcessData(path_to_file, amount_clusters, expected_cluster_length, ccore):
        sample = read_sample(path_to_file);
        
        somsc_instance = somsc(sample, amount_clusters, 100, ccore);
        somsc_instance.process();
        
        clusters = somsc_instance.get_clusters();

        obtained_cluster_sizes = [len(cluster) for cluster in clusters];
        assert len(sample) == sum(obtained_cluster_sizes);
        
        if (expected_cluster_length != None):
            obtained_cluster_sizes.sort();
            expected_cluster_length.sort();
            if (obtained_cluster_sizes != expected_cluster_length):
                print 
            assert obtained_cluster_sizes == expected_cluster_length;
Esempio n. 7
0
def som(arrayNormalizedCharacters,scaler,k):
	
	#from pyclustering.cluster import cluster_visualizer
	
	# Load list of points for cluster analysis
	data = arrayNormalizedCharacters
	# Create instance of SOM-SC algorithm to allocated two clusters
	somsc_instance = somsc(data, k)
	# Run cluster analysis and obtain results
	somsc_instance.process()
	clusters = somsc_instance.get_clusters()
	# Visualize clustering results.
	#visualizer = cluster_visualizer()
	#visualizer.append_clusters(clusters, data)
	#visualizer.show()
	
	clustersResult = []
	k = len(clusters)
	labels = []
	
	for i in range(0,k):
		clustersResult.append([])	
	
	i=0
	for player in arrayNormalizedCharacters:
		j=0
		for cluster in clusters:
			if(i in cluster):
				clustersResult[j].append(arrayNormalizedCharacters[i])
				labels.append(j)
			j= j+1
		i=i+1
	
	for i in range(0,k):
		clustersResult[i] = scaler.inverse_transform(clustersResult[i])
	
	return (clustersResult,labels)