def templateAnimateClusteringResultNoFailure(filename, initial_centers, ccore_flag): sample = read_sample(filename) observer = kmeans_observer() kmeans_instance = kmeans(sample, initial_centers, 0.025, ccore_flag, observer=observer) kmeans_instance.process() kmeans_visualizer.animate_cluster_allocation(sample, observer)
def templateCollectEvolution(filename, initial_centers, number_clusters, ccore_flag): sample = read_sample(filename) observer = kmeans_observer() kmeans_instance = kmeans(sample, initial_centers, 0.025, ccore_flag, observer=observer) kmeans_instance.process() assertion.le(1, len(observer)) for i in range(len(observer)): assertion.le(1, len(observer.get_centers(i))) for center in observer.get_centers(i): assertion.eq(len(sample[0]), len(center)) assertion.le(1, len(observer.get_clusters(i)))
def templateCollectEvolution(filename, initial_centers, number_clusters, ccore_flag): sample = read_sample(filename); observer = kmeans_observer(); kmeans_instance = kmeans(sample, initial_centers, 0.025, ccore_flag, observer=observer); kmeans_instance.process(); assertion.le(1, len(observer)); for i in range(len(observer)): assertion.le(1, len(observer.get_centers(i))); for center in observer.get_centers(i): assertion.eq(len(sample[0]), len(center)); assertion.le(1, len(observer.get_clusters(i)));
def template_clustering(start_centers, path, tolerance=0.25, ccore=True): sample = read_sample(path) observer = kmeans_observer() kmeans_instance = kmeans(sample, start_centers, tolerance, ccore, observer=observer) (ticks, _) = timedcall(kmeans_instance.process) clusters = kmeans_instance.get_clusters() centers = kmeans_instance.get_centers() print("Sample: ", path, "\t\tExecution time: ", ticks, "\n") kmeans_visualizer.show_clusters(sample, clusters, centers, start_centers) kmeans_visualizer.animate_cluster_allocation(sample, observer)
def template_clustering(start_centers, path, tolerance = 0.25, ccore = False): sample = read_sample(path) dimension = len(sample[0]) metric = distance_metric(type_metric.MANHATTAN) observer = kmeans_observer() kmeans_instance = kmeans(sample, start_centers, tolerance, ccore, observer=observer, metric=metric) (ticks, _) = timedcall(kmeans_instance.process) clusters = kmeans_instance.get_clusters() centers = kmeans_instance.get_centers() print("Sample: ", path, "\t\tExecution time: ", ticks, "\n") visualizer = cluster_visualizer_multidim() visualizer.append_clusters(clusters, sample) visualizer.show() if dimension > 3: kmeans_visualizer.show_clusters(sample, clusters, centers, start_centers) kmeans_visualizer.animate_cluster_allocation(sample, observer)