How to use the pyclustering.core.pyclustering_package.pyclustering_package function in pyclustering

To help you get started, we’ve selected a few pyclustering examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github annoviko / pyclustering / pyclustering / core / silhouette_wrapper.py View on Github external
def silhoeutte(sample, clusters, pointer_metric, data_type):
    pointer_data = package_builder(sample, c_double).create()
    pointer_clusters = package_builder(clusters, c_size_t).create()
    c_data_type = convert_data_type(data_type)

    ccore = ccore_library.get()
    ccore.silhouette_algorithm.restype = POINTER(pyclustering_package)
    package = ccore.silhouette_algorithm(pointer_data, pointer_clusters, pointer_metric, c_data_type)

    result = package_extractor(package).extract()
    ccore.free_pyclustering_package(package)

    return result
github annoviko / pyclustering / pyclustering / core / pyclustering_package.py View on Github external
def __create_package(self, dataset):
        dataset_package = pyclustering_package()
        
        if isinstance(dataset, numpy.matrix):
            return self.__create_package_numpy_matrix(dataset_package, dataset)
        
        dataset_package.size = len(dataset)
    
        if len(dataset) == 0:
            dataset_package.type = pyclustering_type_data.PYCLUSTERING_TYPE_UNDEFINED
            dataset_package.data = None
    
            return pointer(dataset_package)
    
        c_data_type = self.__fill_type(dataset_package, dataset)
        self.__fill_data(dataset_package, c_data_type, dataset)
        
        return pointer(dataset_package)
github annoviko / pyclustering / pyclustering / core / kmedians_wrapper.py View on Github external
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]
github annoviko / pyclustering / pyclustering / core / pyclustering_package.py View on Github external
def __create_package_numpy_matrix(self, dataset_package, dataset):
        (rows, cols) = dataset.shape
        
        dataset_package.size = rows
        dataset_package.type = pyclustering_type_data.PYCLUSTERING_TYPE_LIST
        
        package_data = (POINTER(pyclustering_package) * rows)()
        for row_index in range(rows):
            array_package = pyclustering_package()
            array_package.size = cols
            array_package.type = pyclustering_type_data.get_pyclustering_type(self.__c_data_type)
            
            array_object = (self.__c_data_type * cols)()
            for col_index in range(cols):
                array_object[col_index] = self.__c_data_type(dataset[row_index, col_index])
        
            array_package.data = cast(array_object, POINTER(c_void_p))
            package_data[row_index] = pointer(array_package)
            
        dataset_package.data = cast(package_data, POINTER(c_void_p))
        return pointer(dataset_package)
github annoviko / pyclustering / pyclustering / core / mbsas_wrapper.py View on Github external
def mbsas(sample, amount, threshold, metric_pointer):
    pointer_data = package_builder(sample, c_double).create();

    ccore = ccore_library.get();

    ccore.mbsas_algorithm.restype = POINTER(pyclustering_package);
    package = ccore.mbsas_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];
github annoviko / pyclustering / pyclustering / core / agglomerative_wrapper.py View on Github external
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;
github annoviko / pyclustering / pyclustering / core / hhn_wrapper.py View on Github external
def hhn_dynamic_get_peripheral_evolution(ccore_hhn_dynamic_pointer, index_collection):
    ccore = ccore_library.get();

    ccore.hhn_dynamic_get_peripheral_evolution.restype = POINTER(pyclustering_package);
    dynamic_package = ccore.hhn_dynamic_get_peripheral_evolution(ccore_hhn_dynamic_pointer, c_size_t(index_collection));

    result = package_extractor(dynamic_package).extract();
    ccore.free_pyclustering_package(dynamic_package);

    return result;
github annoviko / pyclustering / pyclustering / core / elbow_wrapper.py View on Github external
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])
github annoviko / pyclustering / pyclustering / core / kmedoids_wrapper.py View on Github external
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]
github annoviko / pyclustering / pyclustering / core / metric_wrapper.py View on Github external
along with this program.  If not, see .
@endcond

"""


from pyclustering.core.wrapper import ccore_library

from pyclustering.core.pyclustering_package import package_builder, package_extractor, pyclustering_package

from ctypes import c_double, c_size_t, POINTER, c_void_p, CFUNCTYPE

from pyclustering.utils.metric import type_metric


metric_callback = CFUNCTYPE(c_double, POINTER(pyclustering_package), POINTER(pyclustering_package))


class metric_wrapper:
    def __init__(self, type_metric_code, arguments, func):
        self.__func = lambda p1, p2: func(package_extractor(p1).extract(), package_extractor(p2).extract())

        package_arguments = package_builder(arguments, c_double).create()

        ccore = ccore_library.get()

        ccore.metric_create.restype = POINTER(c_void_p)

        self.__pointer = ccore.metric_create(c_size_t(type_metric_code), package_arguments, metric_callback(self.__func))


    def __del__(self):