def rock(sample, eps, number_clusters, threshold): """ @brief Clustering algorithm ROCK returns allocated clusters and noise that are consisted from input data. @details Calculation is performed via CCORE (C/C++ part of the pyclustering)." @param[in] sample: input data - list of points where each point is represented by list of coordinates. @param[in] eps: connectivity radius (similarity threshold), points are neighbors if distance between them is less than connectivity radius. @param[in] number_clusters: defines number of clusters that should be allocated from the input data set. @param[in] threshold: value that defines degree of normalization that influences on choice of clusters for merging during processing. @return List of allocated clusters, each cluster contains indexes of objects in list of data. """ pointer_data = package_builder(sample, c_double).create(); ccore = ccore_library.get(); ccore.rock_algorithm.restype = POINTER(pyclustering_package); package = ccore.rock_algorithm(pointer_data, c_double(eps), c_size_t(number_clusters), c_double(threshold)); list_of_clusters = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return list_of_clusters;
def templatePackUnpack(self, dataset, c_type_data = None): package_pointer = package_builder(dataset, c_type_data).create(); unpacked_package = package_extractor(package_pointer).extract(); packing_data = dataset; if (isinstance(packing_data, numpy.matrix)): packing_data = dataset.tolist(); assert self.compare_containers(packing_data, unpacked_package);
def hhn_dynamic_get_central_evolution(ccore_hhn_dynamic_pointer, index_collection): ccore = ccore_library.get(); ccore.hhn_dynamic_get_central_evolution.restype = POINTER(pyclustering_package); dynamic_package = ccore.hhn_dynamic_get_central_evolution(ccore_hhn_dynamic_pointer, c_size_t(index_collection)); result = package_extractor(dynamic_package).extract(); ccore.free_pyclustering_package(dynamic_package); return result;
def legion_dynamic_get_inhibitory_output(legion_dynamic_pointer): ccore = ccore_library.get(); ccore.legion_dynamic_get_inhibitory_output.restype = POINTER(pyclustering_package); package = ccore.legion_dynamic_get_inhibitory_output(legion_dynamic_pointer); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result;
def pcnn_dynamic_get_time(dynamic_pointer): ccore = ccore_library.get(); ccore.pcnn_dynamic_get_time.restype = POINTER(pyclustering_package); package = ccore.pcnn_dynamic_get_time(dynamic_pointer); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result;
def cure_get_means(cure_data_pointer): ccore = ccore_library.get(); ccore.cure_get_means.restype = POINTER(pyclustering_package); package = ccore.cure_get_means(cure_data_pointer); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result;
def pcnn_dynamic_allocate_spike_ensembles(dynamic_pointer): ccore = ccore_library.get(); ccore.pcnn_dynamic_allocate_spike_ensembles.restype = POINTER(pyclustering_package); package = ccore.pcnn_dynamic_allocate_spike_ensembles(dynamic_pointer); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result;
def syncpr_dynamic_allocate_sync_ensembles(pointer_dynamic, tolerance): ccore = ccore_library.get(); ccore.syncpr_dynamic_allocate_sync_ensembles.restype = POINTER(pyclustering_package); package = ccore.syncpr_dynamic_allocate_sync_ensembles(pointer_dynamic, c_double(tolerance)); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result;
def syncpr_dynamic_get_output(pointer_dynamic): ccore = ccore_library.get(); ccore.syncpr_dynamic_get_output.restype = POINTER(pyclustering_package); package = ccore.syncpr_dynamic_get_output(pointer_dynamic); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result;
def agglomerative_algorithm(data, number_clusters, link): pointer_data = package_builder(data, c_double).create(); ccore = ccore_library.get(); ccore.agglomerative_algorithm.restype = POINTER(pyclustering_package); package = ccore.agglomerative_algorithm(pointer_data, c_size_t(number_clusters), c_size_t(link)); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result;
def bsas(sample, amount, threshold, metric_pointer): pointer_data = package_builder(sample, c_double).create() ccore = ccore_library.get() ccore.bsas_algorithm.restype = POINTER(pyclustering_package) package = ccore.bsas_algorithm(pointer_data, c_size_t(amount), c_double(threshold), metric_pointer) result = package_extractor(package).extract() ccore.free_pyclustering_package(package) return result[0], result[1]
def ttsas(sample, threshold1, threshold2, metric_pointer): pointer_data = package_builder(sample, c_double).create(); ccore = ccore_library.get(); ccore.ttsas_algorithm.restype = POINTER(pyclustering_package); package = ccore.ttsas_algorithm(pointer_data, c_double(threshold1), c_double(threshold2), metric_pointer); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result[0], result[1];
def silhoeutte(sample, clusters, pointer_metric): pointer_data = package_builder(sample, c_double).create() pointer_clusters = package_builder(clusters, c_size_t).create() ccore = ccore_library.get() ccore.silhouette_algorithm.restype = POINTER(pyclustering_package) package = ccore.silhouette_algorithm(pointer_data, pointer_clusters, pointer_metric) result = package_extractor(package).extract() ccore.free_pyclustering_package(package) return result
def fcm_algorithm(sample, centers, m, tolerance, itermax): pointer_data = package_builder(sample, c_double).create() pointer_centers = package_builder(centers, c_double).create() ccore = ccore_library.get() ccore.fcm_algorithm.restype = POINTER(pyclustering_package) package = ccore.fcm_algorithm(pointer_data, pointer_centers, c_double(m), c_double(tolerance), c_size_t(itermax)) result = package_extractor(package).extract() ccore.free_pyclustering_package(package) return result
def kmedians(sample, centers, tolerance, itermax, metric_pointer): pointer_data = package_builder(sample, c_double).create() pointer_centers = package_builder(centers, c_double).create() ccore = ccore_library.get() ccore.kmedians_algorithm.restype = POINTER(pyclustering_package) package = ccore.kmedians_algorithm(pointer_data, pointer_centers, c_double(tolerance), c_size_t(itermax), metric_pointer) result = package_extractor(package).extract() ccore.free_pyclustering_package(package) return result[0], result[1]
def xmeans(sample, centers, kmax, tolerance, criterion): pointer_data = package_builder(sample, c_double).create(); pointer_centers = package_builder(centers, c_double).create(); ccore = ccore_library.get(); ccore.xmeans_algorithm.restype = POINTER(pyclustering_package); package = ccore.xmeans_algorithm(pointer_data, pointer_centers, c_size_t(kmax), c_double(tolerance), c_uint(criterion)); result = package_extractor(package).extract(); ccore.free_pyclustering_package(package); return result[0], result[1];
def silhoeutte_ksearch(sample, kmin, kmax, allocator): pointer_data = package_builder(sample, c_double).create() ccore = ccore_library.get() ccore.silhouette_ksearch_algorithm.restype = POINTER(pyclustering_package) package = ccore.silhouette_ksearch_algorithm(pointer_data, c_size_t(kmin), c_size_t(kmax), c_size_t(allocator)) results = package_extractor(package).extract() ccore.free_pyclustering_package(package) return (results[silhouette_ksearch_package_indexer.SILHOUETTE_KSEARCH_PACKAGE_INDEX_AMOUNT][0], results[silhouette_ksearch_package_indexer.SILHOUETTE_KSEARCH_PACKAGE_INDEX_SCORE][0], results[silhouette_ksearch_package_indexer.SILHOUETTE_KSEARCH_PACKAGE_INDEX_SCORES])
def kmedoids(sample, medoids, tolerance, itermax, metric_pointer, data_type): pointer_data = package_builder(sample, c_double).create() medoids_package = package_builder(medoids, c_size_t).create() c_data_type = convert_data_type(data_type) ccore = ccore_library.get() ccore.kmedoids_algorithm.restype = POINTER(pyclustering_package) package = ccore.kmedoids_algorithm(pointer_data, medoids_package, c_double(tolerance), c_size_t(itermax), metric_pointer, c_data_type) result = package_extractor(package).extract() ccore.free_pyclustering_package(package) return result[0], result[1]
def dbscan(sample, eps, min_neighbors, data_type): pointer_data = package_builder(sample, c_double).create() c_data_type = convert_data_type(data_type) ccore = ccore_library.get() ccore.dbscan_algorithm.restype = POINTER(pyclustering_package) package = ccore.dbscan_algorithm(pointer_data, c_double(eps), c_size_t(min_neighbors), c_data_type) list_of_clusters = package_extractor(package).extract() ccore.free_pyclustering_package(package) noise = list_of_clusters[len(list_of_clusters) - 1] list_of_clusters.remove(noise) return list_of_clusters, noise
def clique(sample, intervals, threshold): pointer_data = package_builder(sample, c_double).create() ccore = ccore_library.get() ccore.clique_algorithm.restype = POINTER(pyclustering_package) package = ccore.clique_algorithm(pointer_data, c_size_t(intervals), c_size_t(threshold)) results = package_extractor(package).extract() ccore.free_pyclustering_package(package) return (results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_CLUSTERS], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_NOISE], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_LOGICAL_LOCATION], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_MAX_CORNER], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_MIN_CORNER], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_BLOCK_POINTS])
def optics(sample, radius, minimum_neighbors, amount_clusters): amount = amount_clusters if (amount is None): amount = 0 pointer_data = package_builder(sample, c_double).create() ccore = load_core() ccore.optics_algorithm.restype = POINTER(pyclustering_package) package = ccore.optics_algorithm(pointer_data, c_double(radius), c_size_t(minimum_neighbors), c_size_t(amount)) results = package_extractor(package).extract() ccore.free_pyclustering_package(package) return (results[optics_package_indexer.OPTICS_PACKAGE_INDEX_CLUSTERS], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_NOISE], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_ORDERING], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_RADIUS][0])
def elbow(sample, kmin, kmax, initializer): pointer_data = package_builder(sample, c_double).create() ccore = ccore_library.get() if initializer == elbow_center_initializer.KMEANS_PLUS_PLUS: ccore.elbow_method_ikpp.restype = POINTER(pyclustering_package) package = ccore.elbow_method_ikpp(pointer_data, c_size_t(kmin), c_size_t(kmax)) elif initializer == elbow_center_initializer.RANDOM: ccore.elbow_method_irnd.restype = POINTER(pyclustering_package) package = ccore.elbow_method_irnd(pointer_data, c_size_t(kmin), c_size_t(kmax)) else: raise ValueError("Not supported type of center initializer '" + str(initializer) + "'.") results = package_extractor(package).extract() ccore.free_pyclustering_package(package) return (results[elbow_package_indexer.ELBOW_PACKAGE_INDEX_AMOUNT][0], results[elbow_package_indexer.ELBOW_PACKAGE_INDEX_WCE])
def antmean_clustering_process(params, count_clusters, samples): ccore = load_core() algorithm_params = c_antcolony_clustering_parameters() algorithm_params.ro = c_double(params.ro) algorithm_params.pheramone_init = c_double(params.pheramone_init) algorithm_params.iterations = c_uint(params.iterations) algorithm_params.count_ants = c_uint(params.count_ants) algorithm_params = pointer(algorithm_params) sample_package = package_builder(samples, c_double).create() ccore.antmean_algorithm.restype = POINTER(pyclustering_package) package = ccore.antmean_algorithm(sample_package, algorithm_params, count_clusters) result = package_extractor(package).extract() ccore.free_pyclustering_package(package) return result
def elbow(sample, kmin, kmax, kstep, initializer, random_state): random_state = random_state or -1 pointer_data = package_builder(sample, c_double).create() ccore = ccore_library.get() if initializer == elbow_center_initializer.KMEANS_PLUS_PLUS: ccore.elbow_method_ikpp.restype = POINTER(pyclustering_package) package = ccore.elbow_method_ikpp(pointer_data, c_size_t(kmin), c_size_t(kmax), c_size_t(kstep), c_longlong(random_state)) elif initializer == elbow_center_initializer.RANDOM: ccore.elbow_method_irnd.restype = POINTER(pyclustering_package) package = ccore.elbow_method_irnd(pointer_data, c_size_t(kmin), c_size_t(kmax), c_size_t(kstep), c_longlong(random_state)) else: raise ValueError("Not supported type of center initializer '" + str(initializer) + "'.") results = package_extractor(package).extract() ccore.free_pyclustering_package(package) if isinstance(results, bytes): raise RuntimeError(results.decode('utf-8')) return (results[elbow_package_indexer.ELBOW_PACKAGE_INDEX_AMOUNT][0], results[elbow_package_indexer.ELBOW_PACKAGE_INDEX_WCE])
def clique(sample, intervals, threshold): pointer_data = package_builder(sample, c_double).create() ccore = ccore_library.get() ccore.clique_algorithm.restype = POINTER(pyclustering_package) package = ccore.clique_algorithm(pointer_data, c_size_t(intervals), c_size_t(threshold)) results = package_extractor(package).extract() ccore.free_pyclustering_package(package) if isinstance(results, bytes): raise RuntimeError(results.decode('utf-8')) return ( results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_CLUSTERS], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_NOISE], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_LOGICAL_LOCATION], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_MAX_CORNER], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_MIN_CORNER], results[clique_package_indexer.CLIQUE_PACKAGE_INDEX_BLOCK_POINTS])
def optics(sample, radius, minimum_neighbors, amount_clusters, data_type): amount = amount_clusters if amount is None: amount = 0 pointer_data = package_builder(sample, c_double).create() c_data_type = convert_data_type(data_type) ccore = ccore_library.get() ccore.optics_algorithm.restype = POINTER(pyclustering_package) package = ccore.optics_algorithm(pointer_data, c_double(radius), c_size_t(minimum_neighbors), c_size_t(amount), c_data_type) results = package_extractor(package).extract() ccore.free_pyclustering_package(package) return (results[optics_package_indexer.OPTICS_PACKAGE_INDEX_CLUSTERS], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_NOISE], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_ORDERING], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_RADIUS][0], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_OPTICS_OBJECTS_INDEX], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_OPTICS_OBJECTS_CORE_DISTANCE], results[optics_package_indexer.OPTICS_PACKAGE_INDEX_OPTICS_OBJECTS_REACHABILITY_DISTANCE])
def templatePackUnpack(self, dataset, c_type_data=None): package_pointer = package_builder(dataset, c_type_data).create() unpacked_package = package_extractor(package_pointer).extract() assert self.compare_containers(dataset, unpacked_package)