@@ 101-130 (lines=30) @@ | ||
98 | """ |
|
99 | ||
100 | ||
101 | def __init__(self, data, initial_index_medoids, tolerance=0.001, ccore=True, **kwargs): |
|
102 | """! |
|
103 | @brief Constructor of clustering algorithm K-Medoids. |
|
104 | ||
105 | @param[in] data (list): Input data that is presented as list of points (objects), each point should be represented by list or tuple. |
|
106 | @param[in] initial_index_medoids (list): Indexes of intial medoids (indexes of points in input data). |
|
107 | @param[in] tolerance (double): Stop condition: if maximum value of distance change of medoids of clusters is less than tolerance than algorithm will stop processing. |
|
108 | @param[in] ccore (bool): If specified than CCORE library (C++ pyclustering library) is used for clustering instead of Python code. |
|
109 | @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'metric', 'data_type'). |
|
110 | ||
111 | <b>Keyword Args:</b><br> |
|
112 | - metric (distance_metric): Metric that is used for distance calculation between two points. |
|
113 | - data_type (string): Data type of input sample 'data' that is processed by the algorithm ('points', 'distance_matrix'). |
|
114 | ||
115 | """ |
|
116 | self.__pointer_data = data |
|
117 | self.__clusters = [] |
|
118 | self.__medoid_indexes = initial_index_medoids |
|
119 | self.__tolerance = tolerance |
|
120 | ||
121 | self.__metric = kwargs.get('metric', distance_metric(type_metric.EUCLIDEAN_SQUARE)) |
|
122 | if self.__metric is None: |
|
123 | self.__metric = distance_metric(type_metric.EUCLIDEAN_SQUARE) |
|
124 | ||
125 | self.__data_type = kwargs.get('data_type', 'points') |
|
126 | self.__distance_calculator = self.__create_distance_calculator() |
|
127 | ||
128 | self.__ccore = ccore and self.__metric.get_type() != type_metric.USER_DEFINED |
|
129 | if self.__ccore: |
|
130 | self.__ccore = ccore_library.workable() |
|
131 | ||
132 | ||
133 | def process(self): |
@@ 62-87 (lines=26) @@ | ||
59 | ||
60 | """ |
|
61 | ||
62 | def __init__(self, data, initial_centers, tolerance=0.001, ccore=True, **kwargs): |
|
63 | """! |
|
64 | @brief Constructor of clustering algorithm K-Medians. |
|
65 | ||
66 | @param[in] data (list): Input data that is presented as list of points (objects), each point should be represented by list or tuple. |
|
67 | @param[in] initial_centers (list): Initial coordinates of medians of clusters that are represented by list: [center1, center2, ...]. |
|
68 | @param[in] tolerance (double): Stop condition: if maximum value of change of centers of clusters is less than tolerance than algorithm will stop processing |
|
69 | @param[in] ccore (bool): Defines should be CCORE library (C++ pyclustering library) used instead of Python code or not. |
|
70 | @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'metric'). |
|
71 | ||
72 | <b>Keyword Args:</b><br> |
|
73 | - metric (distance_metric): Metric that is used for distance calculation between two points. |
|
74 | ||
75 | """ |
|
76 | self.__pointer_data = data |
|
77 | self.__clusters = [] |
|
78 | self.__medians = initial_centers[:] |
|
79 | self.__tolerance = tolerance |
|
80 | ||
81 | self.__metric = kwargs.get('metric', distance_metric(type_metric.EUCLIDEAN_SQUARE)) |
|
82 | if self.__metric is None: |
|
83 | self.__metric = distance_metric(type_metric.EUCLIDEAN_SQUARE) |
|
84 | ||
85 | self.__ccore = ccore and self.__metric.get_type() != type_metric.USER_DEFINED |
|
86 | if self.__ccore: |
|
87 | self.__ccore = ccore_library.workable() |
|
88 | ||
89 | ||
90 | def process(self): |