|
1
|
|
|
"""!
|
|
2
|
|
|
|
|
3
|
|
|
@brief Data dimension analyser.
|
|
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
|
|
|
class dimension_info:
|
|
28
|
|
|
"""!
|
|
29
|
|
|
"""
|
|
30
|
|
|
|
|
31
|
|
|
def __init__(self, data):
|
|
32
|
|
|
if (data is None):
|
|
33
|
|
|
raise NameError("Information about dimension of 'None' cannot be obtained");
|
|
34
|
|
|
|
|
35
|
|
|
self.__data = data;
|
|
36
|
|
|
self.__dimensions = None;
|
|
37
|
|
|
self.__maximum_dimension = None;
|
|
38
|
|
|
self.__minimum_dimension = None;
|
|
39
|
|
|
self.__width_dimension = None;
|
|
40
|
|
|
self.__center_dimension = None;
|
|
41
|
|
|
|
|
42
|
|
|
|
|
43
|
|
|
def get_dimensions(self):
|
|
44
|
|
|
if (self.__dimensions is None):
|
|
45
|
|
|
self.__calculate_dimension();
|
|
46
|
|
|
|
|
47
|
|
|
return self.__dimensions;
|
|
48
|
|
|
|
|
49
|
|
|
|
|
50
|
|
|
def get_maximum_coordinate(self):
|
|
51
|
|
|
if (self.__maximum_dimension is None):
|
|
52
|
|
|
self.__calculate_maxmin_dimension_coordinate();
|
|
53
|
|
|
|
|
54
|
|
|
return self.__maximum_dimension;
|
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
def get_minimum_coordinate(self):
|
|
58
|
|
|
if (self.__minimum_dimension is None):
|
|
59
|
|
|
self.__calculate_maxmin_dimension_coordinate();
|
|
60
|
|
|
|
|
61
|
|
|
return self.__minimum_dimension;
|
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
def get_width(self):
|
|
65
|
|
|
if (self.__width_dimension is None):
|
|
66
|
|
|
self.__calculate_width();
|
|
67
|
|
|
|
|
68
|
|
|
return self.__width_dimension;
|
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
def get_center(self):
|
|
72
|
|
|
if (self.__center_dimension is None):
|
|
73
|
|
|
self.__calculate_center();
|
|
74
|
|
|
|
|
75
|
|
|
return self.__center_dimension;
|
|
76
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
def __calculate_dimension(self):
|
|
79
|
|
|
self.__dimensions = len(self.__data[0]);
|
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
def __calculate_maxmin_dimension_coordinate(self):
|
|
83
|
|
|
self.__maximum_dimension = [self.__data[0][i] for i in range(self.get_dimensions())];
|
|
84
|
|
|
self.__minimum_dimension = [self.__data[0][i] for i in range(self.get_dimensions())];
|
|
85
|
|
|
|
|
86
|
|
|
for i in range(len(self.__data)):
|
|
87
|
|
|
for dim in range(self.get_dimensions()):
|
|
88
|
|
|
if (self.__maximum_dimension[dim] < self.__data[i][dim]):
|
|
89
|
|
|
self.__maximum_dimension[dim] = self.__data[i][dim];
|
|
90
|
|
|
elif (self.__minimum_dimension[dim] > self.__data[i][dim]):
|
|
91
|
|
|
self.__minimum_dimension[dim] = self.__data[i][dim];
|
|
92
|
|
|
|
|
93
|
|
|
|
|
94
|
|
|
def __calculate_width(self):
|
|
95
|
|
|
self.__width_dimension = [0] * self.get_dimensions();
|
|
96
|
|
|
for dim in range(self.get_dimensions()):
|
|
97
|
|
|
self.__width_dimension[dim] = self.get_maximum_coordinate()[dim] - self.get_minimum_coordinate()[dim];
|
|
98
|
|
|
|
|
99
|
|
|
|
|
100
|
|
|
def __calculate_center(self):
|
|
101
|
|
|
self.__center_dimension = [0] * self.get_dimensions();
|
|
102
|
|
|
for dim in range(self.get_dimensions()):
|
|
103
|
|
|
self.__center_dimension[dim] = (self.get_maximum_coordinate()[dim] + self.get_minimum_coordinate()[dim]) / 2.0;
|
|
104
|
|
|
|