1
|
|
|
"""!
|
2
|
|
|
|
3
|
|
|
@brief Wrapper for CCORE library (part of this project).
|
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 *;
|
|
|
|
|
27
|
|
|
|
28
|
|
|
from pyclustering.core.definitions import *;
|
|
|
|
|
29
|
|
|
|
30
|
|
|
|
31
|
|
|
# API that is required for interaction with DLL.
|
32
|
|
|
def create_pointer_data(sample):
|
33
|
|
|
"Allocates memory for representing input data for processing that is described by structure 'data_representation' and returns pointer this structure."
|
34
|
|
|
|
35
|
|
|
"(in) sample - dataset for processing."
|
|
|
|
|
36
|
|
|
|
37
|
|
|
"Returns pointer to the data for processing."
|
|
|
|
|
38
|
|
|
|
39
|
|
|
input_data = data_representation();
|
40
|
|
|
input_data.number_objects = len(sample);
|
41
|
|
|
input_data.dimension = len(sample[0]);
|
42
|
|
|
|
43
|
|
|
pointer_objects = (POINTER(c_double) * input_data.number_objects)();
|
44
|
|
|
|
45
|
|
|
for index in range(0, input_data.number_objects):
|
46
|
|
|
point = (c_double * input_data.dimension)();
|
47
|
|
|
for dimension in range(0, input_data.dimension):
|
48
|
|
|
point[dimension] = sample[index][dimension];
|
49
|
|
|
|
50
|
|
|
pointer_objects[index] = cast(point, POINTER(c_double));
|
51
|
|
|
|
52
|
|
|
input_data.pointer_objects = cast(pointer_objects, POINTER(POINTER(c_double)));
|
53
|
|
|
input_data = pointer(input_data);
|
54
|
|
|
|
55
|
|
|
return input_data;
|
56
|
|
|
|
57
|
|
|
|
58
|
|
|
# Implemented algorithms.
|
59
|
|
|
"CCORE Interface for HSYNCNET oscillatory network"
|
|
|
|
|
60
|
|
|
|
61
|
|
|
def hsyncnet_create_network(sample, number_clusters, initial_phases, initial_neighbors, increase_persent):
|
62
|
|
|
pointer_data = create_pointer_data(sample);
|
63
|
|
|
|
64
|
|
|
ccore = cdll.LoadLibrary(PATH_DLL_CCORE_64);
|
65
|
|
|
ccore.hsyncnet_create_network.restype = POINTER(c_void_p);
|
66
|
|
|
pointer_network = ccore.hsyncnet_create_network(pointer_data, c_uint(number_clusters), c_uint(initial_phases), c_uint(initial_neighbors), c_double(increase_persent));
|
67
|
|
|
|
68
|
|
|
return pointer_network;
|
69
|
|
|
|
70
|
|
|
|
71
|
|
|
def hsyncnet_destroy_network(pointer_network):
|
72
|
|
|
ccore = cdll.LoadLibrary(PATH_DLL_CCORE_64);
|
73
|
|
|
ccore.hsyncnet_destroy_network(pointer_network);
|
74
|
|
|
|
75
|
|
|
|
76
|
|
|
def hsyncnet_process(network_pointer, order, solution, collect_dynamic):
|
77
|
|
|
ccore = cdll.LoadLibrary(PATH_DLL_CCORE_64);
|
78
|
|
|
ccore.hsyncnet_process.restype = POINTER(c_void_p);
|
79
|
|
|
return ccore.hsyncnet_process(network_pointer, c_double(order), c_uint(solution), c_bool(collect_dynamic));
|
80
|
|
|
|
81
|
|
|
|
82
|
|
|
def hsyncnet_analyser_destroy(pointer_analyser):
|
83
|
|
|
ccore = cdll.LoadLibrary(PATH_DLL_CCORE_64);
|
84
|
|
|
ccore.syncnet_analyser_destroy(pointer_analyser);
|
85
|
|
|
|
86
|
|
|
|