|
1
|
|
|
"""! |
|
2
|
|
|
|
|
3
|
|
|
@brief CCORE Wrapper for clustering Ant Means 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
|
|
|
|
|
27
|
|
|
from pyclustering.core.wrapper import *; |
|
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
import types; |
|
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
class c_antcolony_clustering_parameters(Structure): |
|
33
|
|
|
""" |
|
34
|
|
|
double ro; |
|
35
|
|
|
double pheramone_init; |
|
36
|
|
|
unsigned int iterations; |
|
37
|
|
|
unsigned int count_ants; |
|
38
|
|
|
|
|
39
|
|
|
""" |
|
40
|
|
|
_fields_ = [("ro" , c_double), |
|
41
|
|
|
("pheramone_init" , c_double), |
|
42
|
|
|
("iterations" , c_uint), |
|
43
|
|
|
("count_ants" , c_uint) ]; |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
def antmean_clustering_process(params, count_clusters, samples): |
|
47
|
|
|
ccore = cdll.LoadLibrary(PATH_DLL_CCORE_64); |
|
48
|
|
|
|
|
49
|
|
|
algorithm_params = c_antcolony_clustering_parameters(); |
|
50
|
|
|
algorithm_params.ro = c_double(params.ro); |
|
51
|
|
|
algorithm_params.pheramone_init = c_double(params.pheramone_init); |
|
52
|
|
|
algorithm_params.iterations = c_uint(params.iterations); |
|
53
|
|
|
algorithm_params.count_ants = c_uint(params.count_ants); |
|
54
|
|
|
|
|
55
|
|
|
algorithm_params = pointer(algorithm_params); |
|
56
|
|
|
|
|
57
|
|
|
p_samples = create_pointer_data(samples) |
|
58
|
|
|
|
|
59
|
|
|
""" |
|
60
|
|
|
Run algorithm |
|
61
|
|
|
""" |
|
|
|
|
|
|
62
|
|
|
res = ccore.ant_mean_clustering(p_samples, algorithm_params, count_clusters) |
|
63
|
|
|
res = cast(res, POINTER(clustering_result)); |
|
64
|
|
|
|
|
65
|
|
|
""" |
|
66
|
|
|
Cast result to python view |
|
67
|
|
|
""" |
|
|
|
|
|
|
68
|
|
|
pointer_data = cast(res[0].pointer_clusters, POINTER(cluster_representation)) |
|
69
|
|
|
num_clusters = res[0].number_clusters |
|
70
|
|
|
|
|
71
|
|
|
pyResult = [[] for i in range(num_clusters)] |
|
72
|
|
|
|
|
73
|
|
|
for i in range(num_clusters): |
|
74
|
|
|
for j in range(pointer_data[i].number_objects): |
|
75
|
|
|
pyResult[i].append(pointer_data[i].pointer_objects[j]) |
|
76
|
|
|
|
|
77
|
|
|
return pyResult |