gpu实现快速搜索和密度峰值的聚类。
ImageAlgoKD的Python项目详细描述
通用图像算法
图像算法是一种基于fast search and find of density peaks的聚类算法。 与dbscan等其他流行的聚类方法相比,图像算法最突出的优点之一是具有高度的并行性。该存储库是通用图像算法的一个实现,支持强大而容易的gpu加速。
目前,实现包括三个后端:numpy、cuda和opencl。
backend | dependency | Support Platform | Support Device |
---|---|---|---|
^{ | None | Mac/Linux/Windows | CPU |
^{ | pycuda | Linux | Only NVIDIA GPU |
^{ | pyopencl | Mac | NVIDIA/AMD/Intel GPU, multi-core CPU |
经过测试,这三个后端都给出了相同的聚类结果。因此,用户可以根据自己的目的自由选择更快、更容易的。
对于这三种后端,可以采用两种数据结构:平面列表和kdbin。KDBin,K空间中的桶,容纳空间桶中的K空间中的点,具有动态仓分布和柔性仓容量。技术上,它使用散列图和一组存储器引用来获得最接近的相邻容器和内部点,使得每个点的邻域查询是O(1)复杂度。性能测试表明,采用kdbin数据结构进行密度计算具有很强的加速性。
supported data structure | ^{ | ^{ |
---|---|---|
^{ | list/bin | list/bin |
^{ | list/bin | list |
^{ | list/bin | list |
对于密度Rho计算,测试的性能如下所示。
待办事项列表
- []通过'merge sorted list'计算cuda/opencl中的
rhorank
进行并行排序。 - []支持
nh
在cuda/opencl中最近的相邻存储箱中搜索
安装
pip install ImageAlgoKD
关于依赖项,numpy后端不需要依赖项。而且它通常在处理小数据集方面做得很好,不需要额外的包。但是,对于想要在cuda或opencl后端使用gpu加速的用户,需要额外的依赖性。
# if want to use opencl backend pip install pyopencl # if want to use CUDA backend pip install pycuda
快速启动
该模块的主要用途如下 首先,为k维导入imagealgo类
fromImageAlgoKDimport*
使用算法参数声明imagealgokd的实例。然后给它输入数据点。
ia=ImageAlgoKD(MAXDISTANCE=20,KERNEL_R=1.0)ia.setInputsPoints(Points(np.genfromtxt("../data/basic.csv",delimiter=',')))
然后在输入数据点上运行集群。
ia.run("numpy")# ia.run("opencl") or ia.run("cuda") if want run in parallel
最后,可以通过
ia.points.clusterID
算法参数
Parameters | Comments | Default Value |
---|---|---|
MAXDISTANCE | the separation distance of the point with highest density. | 10.0 |
KERNEL_R | 'd_c' in density calculation | 1.0 |
KERNEL_R_NORM | 'd_0' in density calculation | 1.0 |
KERNEL_R_POWER | 'k' in density calculation. | 0.0 |
DECISION_RHO_KAPPA | the ratio of density threshold of seeds to the highest density | 4.0 |
DECISION_NHD | the separation threshold of seeds | 1.0 |
CONTINUITY_NHD | the separation threshold of continuous clusters | 1.0 |
其中密度定义为
示例
一、基本
对从两个高斯分布和噪声中采样的1000个玩具二维点执行ia聚类。玩具数据在data/basic.csv
中,而相应的jupyter笔记本可以在examples/
中找到here。
二。mnist
在1000个mnist 28x28维点上执行ia聚类。mnist数据在data/mnist.csv
中,而相应的jupyter笔记本可以在examples/
中找到here。
三、HgCal这是一个10π介子的事件,在cms-hgcal中能量为300gev。三维交互可视化可以找到here。此外,对于堆积事件,here是一个300gevπ介子,具有pu200事件。pu200事件通常包括大约200k hgvcal重建的检测器点击,该点击被输入ia集群
推荐PyPI第三方库
这是一个10π介子的事件,在cms-hgcal中能量为300gev。三维交互可视化可以找到here。此外,对于堆积事件,here是一个300gevπ介子,具有pu200事件。pu200事件通常包括大约200k hgvcal重建的检测器点击,该点击被输入ia集群