How to use the pyclustering.core.wrapper.ccore_library 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 / 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 / nnet / som.py View on Github external
def __setstate__(self, som_state):
        """
        @brief Set state of SOM network that can be used to load network.

        """
        if som_state['ccore'] is True and ccore_library.workable():
            self.__upload_dump_to_ccore(som_state['state'])
        else:
            self.__upload_dump_to_python(som_state['state'])
github annoviko / pyclustering / pyclustering / core / wrapper.py View on Github external
"Probably library has not been successfully installed ('" + sys.platform + "', '" + platform.architecture()[0] + "').\n" + 
                  "Falling back on python implementation.\n" +
                  "For more information, contact 'pyclustering@yandex.ru'.")
            
            return None

        ccore_library.__library = cdll.LoadLibrary(PATH_PYCLUSTERING_CCORE_LIBRARY)
        if ccore_library.__check_library_integrity() is False:
            print("Impossible to mark ccore as workable due to compatibility issues " +
                  "('" + sys.platform + "', '" + platform.architecture()[0] + "').\n" + 
                  "Falling back on python implementation.\n" +
                  "For more information, contact 'pyclustering@yandex.ru'.")
            
            return None

        result, version = ccore_library.__check_library_version()
        if result is False:
            print("Incompatible ccore version of pyclustering library is being used ('" + version +"' instead '" + ccore_library_version + "').\n" +
                  "Probably library has not been successfully installed.\n" +
                  "Please, contact 'pyclustering@yandex.ru'.")

        return ccore_library.__library
github annoviko / pyclustering / pyclustering / core / wrapper.py View on Github external
def get():
        if not ccore_library.__library:
            ccore_library.initialize()

        return ccore_library.__library
github annoviko / pyclustering / pyclustering / cluster / cure.py View on Github external
"""
        
        self.__pointer_data = self.__prepare_data_points(data)
        
        self.__clusters = None
        self.__representors = None
        self.__means = None
        
        self.__number_cluster = number_cluster
        self.__number_represent_points = number_represent_points
        self.__compression = compression

        self.__ccore = ccore
        if self.__ccore:
            self.__ccore = ccore_library.workable()

        self.__validate_arguments()

github annoviko / pyclustering / pyclustering / core / wrapper.py View on Github external
def initialize():
        ccore_library.__initialized = True
        
        if PATH_PYCLUSTERING_CCORE_LIBRARY is None:
            print("The pyclustering ccore is not supported for platform '" + sys.platform + "' (" + platform.architecture()[0] + ").\n" + 
                  "Falling back on python implementation.\n" +
                  "For more information, contact 'pyclustering@yandex.ru'.")
            
            return None
    
        if os.path.exists(PATH_PYCLUSTERING_CCORE_LIBRARY) is False:
            print("The pyclustering ccore is not found (expected core location: '" + PATH_PYCLUSTERING_CCORE_LIBRARY + "').\n" + 
                  "Probably library has not been successfully installed ('" + sys.platform + "', '" + platform.architecture()[0] + "').\n" + 
                  "Falling back on python implementation.\n" +
                  "For more information, contact 'pyclustering@yandex.ru'.")
            
            return None
github annoviko / pyclustering / pyclustering / core / kmeans_wrapper.py View on Github external
def kmeans(sample, centers, tolerance, itermax, observe, metric_pointer):
    pointer_data = package_builder(sample, c_double).create()
    pointer_centers = package_builder(centers, c_double).create()
    
    ccore = ccore_library.get()
    
    ccore.kmeans_algorithm.restype = POINTER(pyclustering_package)
    package = ccore.kmeans_algorithm(pointer_data, pointer_centers, c_double(tolerance), c_size_t(itermax), c_bool(observe), metric_pointer)
    
    result = package_extractor(package).extract()
    ccore.free_pyclustering_package(package)
    
    return result
github annoviko / pyclustering / pyclustering / core / rock_wrapper.py View on Github external
"""
    @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;