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
|
|
|
from pyclustering.core.pyclustering_package import pyclustering_package, package_builder, package_extractor; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
class c_antcolony_clustering_parameters(Structure): |
32
|
|
|
""" |
33
|
|
|
double ro; |
34
|
|
|
double pheramone_init; |
35
|
|
|
unsigned int iterations; |
36
|
|
|
unsigned int count_ants; |
37
|
|
|
|
38
|
|
|
""" |
39
|
|
|
_fields_ = [("ro" , c_double), |
40
|
|
|
("pheramone_init" , c_double), |
41
|
|
|
("iterations" , c_uint), |
42
|
|
|
("count_ants" , c_uint) ]; |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
def antmean_clustering_process(params, count_clusters, samples): |
46
|
|
|
ccore = load_core(); |
47
|
|
|
|
48
|
|
|
algorithm_params = c_antcolony_clustering_parameters(); |
49
|
|
|
algorithm_params.ro = c_double(params.ro); |
50
|
|
|
algorithm_params.pheramone_init = c_double(params.pheramone_init); |
51
|
|
|
algorithm_params.iterations = c_uint(params.iterations); |
52
|
|
|
algorithm_params.count_ants = c_uint(params.count_ants); |
53
|
|
|
|
54
|
|
|
algorithm_params = pointer(algorithm_params); |
55
|
|
|
|
56
|
|
|
sample_package = package_builder(samples, c_double).create(); |
57
|
|
|
|
58
|
|
|
ccore.antmean_algorithm.restype = POINTER(pyclustering_package); |
59
|
|
|
package = ccore.antmean_algorithm(sample_package, algorithm_params, count_clusters); |
60
|
|
|
|
61
|
|
|
result = package_extractor(package).extract(); |
62
|
|
|
ccore.free_pyclustering_package(package); |
63
|
|
|
|
64
|
|
|
return result; |
65
|
|
|
|