|
1
|
|
|
"""! |
|
2
|
|
|
|
|
3
|
|
|
@brief CCORE Wrapper for ROCK algorithm. |
|
4
|
|
|
|
|
5
|
|
|
@authors Andrei Novikov ([email protected]) |
|
6
|
|
|
@date 2014-2017 |
|
7
|
|
|
@copyright GNU Public License |
|
8
|
|
|
|
|
9
|
|
|
@cond GNU_PUBLIC_LICENSE |
|
10
|
|
|
PyClustering is free software: you can redistribute it and/or modify |
|
11
|
|
|
it under the terms of the GNU General Public License as published by |
|
12
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
13
|
|
|
(at your option) any later version. |
|
14
|
|
|
|
|
15
|
|
|
PyClustering is distributed in the hope that it will be useful, |
|
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
GNU General Public License for more details. |
|
19
|
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License |
|
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
@endcond |
|
23
|
|
|
|
|
24
|
|
|
""" |
|
25
|
|
|
|
|
26
|
|
|
from ctypes import cdll, c_double, c_size_t, POINTER; |
|
27
|
|
|
|
|
28
|
|
|
from pyclustering.core.wrapper import PATH_DLL_CCORE_64, create_pointer_data, extract_pyclustering_package, pyclustering_package; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
def rock(sample, eps, number_clusters, threshold): |
|
32
|
|
|
""" |
|
33
|
|
|
@brief Clustering algorithm ROCK returns allocated clusters and noise that are consisted from input data. |
|
34
|
|
|
@details Calculation is performed via CCORE (C/C++ part of the pyclustering)." |
|
35
|
|
|
|
|
36
|
|
|
@param[in] sample: input data - list of points where each point is represented by list of coordinates. |
|
37
|
|
|
@param[in] eps: connectivity radius (similarity threshold), points are neighbors if distance between them is less than connectivity radius. |
|
38
|
|
|
@param[in] number_clusters: defines number of clusters that should be allocated from the input data set. |
|
39
|
|
|
@param[in] threshold: value that defines degree of normalization that influences on choice of clusters for merging during processing. |
|
40
|
|
|
|
|
41
|
|
|
@return List of allocated clusters, each cluster contains indexes of objects in list of data. |
|
42
|
|
|
|
|
43
|
|
|
""" |
|
44
|
|
|
|
|
45
|
|
|
pointer_data = create_pointer_data(sample); |
|
46
|
|
|
|
|
47
|
|
|
ccore = cdll.LoadLibrary(PATH_DLL_CCORE_64); |
|
48
|
|
|
|
|
49
|
|
|
ccore.rock_algorithm.restype = POINTER(pyclustering_package); |
|
50
|
|
|
package = ccore.rock_algorithm(pointer_data, c_double(eps), c_size_t(number_clusters), c_double(threshold)); |
|
51
|
|
|
|
|
52
|
|
|
list_of_clusters = extract_pyclustering_package(package); |
|
53
|
|
|
ccore.free_pyclustering_package(package); |
|
54
|
|
|
|
|
55
|
|
|
return list_of_clusters; |