Completed
Push — master ( e161a0...2b74d0 )
by Andrei
01:28
created

optics()   A

Complexity

Conditions 2

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
1
"""!
2
3
@brief CCORE Wrapper for OPTICS 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;
27
28
from pyclustering.core.wrapper import PATH_DLL_CCORE_64, create_pointer_data, extract_pyclustering_package;
29
30
31
class optics_package_indexer:
32
    OPTICS_PACKAGE_INDEX_CLUSTERS = 0;
33
    OPTICS_PACKAGE_INDEX_NOISE = 1;
34
    OPTICS_PACKAGE_INDEX_ORDERING = 2;
35
    OPTICS_PACKAGE_INDEX_RADIUS = 3;
36
37
38
def optics(sample, radius, minimum_neighbors, amount_clusters):
39
    amount = amount_clusters;
40
    if (amount is None):
41
        amount = 0;
42
        
43
    pointer_data = create_pointer_data(sample);
44
    
45
    ccore = cdll.LoadLibrary(PATH_DLL_CCORE_64);
46
    package = ccore.optics_algorithm(pointer_data, c_double(radius), c_size_t(minimum_neighbors), c_size_t(amount));
47
48
    results = extract_pyclustering_package(package);
49
    ccore.free_pyclustering_package(package);
50
51
    return (results[optics_package_indexer.OPTICS_PACKAGE_INDEX_CLUSTERS], 
52
            results[optics_package_indexer.OPTICS_PACKAGE_INDEX_NOISE], 
53
            results[optics_package_indexer.OPTICS_PACKAGE_INDEX_ORDERING],
54
            results[optics_package_indexer.OPTICS_PACKAGE_INDEX_RADIUS][0]);