C++ API Reference for Intel® Data Analytics Acceleration Library 2020 Update 1

kmeans_types.h
1 /* file: kmeans_types.h */
2 /*******************************************************************************
3 * Copyright 2014-2020 Intel Corporation
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *******************************************************************************/
17 
18 /*
19 //++
20 // Implementation of K-Means algorithm interface.
21 //--
22 */
23 
24 #ifndef __KMEANS_TYPES_H__
25 #define __KMEANS_TYPES_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "data_management/data/numeric_table.h"
29 #include "data_management/data/homogen_numeric_table.h"
30 #include "services/daal_defines.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
43 namespace kmeans
44 {
49 enum Method
50 {
51  lloydDense = 0,
52  defaultDense = 0,
53  lloydCSR = 1
54 };
55 
60 enum DistanceType
61 {
62  euclidean,
63  lastDistanceType = euclidean
64 };
65 
70 enum InputId
71 {
72  data,
73  inputCentroids,
74  lastInputId = inputCentroids
75 };
76 
81 enum MasterInputId
82 {
83  partialResults,
84  lastMasterInputId = partialResults
85 };
86 
91 enum PartialResultId
92 {
93  nObservations,
94  partialSums,
95  partialObjectiveFunction,
96  partialGoalFunction = partialObjectiveFunction,
97  partialAssignments,
98  partialCandidatesDistances,
99  partialCandidatesCentroids,
100  lastPartialResultId = partialCandidatesCentroids
101 };
102 
107 enum ResultId
108 {
109  centroids,
110  assignments,
111  objectiveFunction,
112  goalFunction = objectiveFunction,
113  nIterations,
114  lastResultId = nIterations
115 };
116 
120 namespace interface1
121 {
130 /* [Parameter source code] */
131 struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
132 {
138  Parameter(size_t _nClusters, size_t _maxIterations);
139 
144  Parameter(const Parameter &other);
145 
146  size_t nClusters;
147  size_t maxIterations;
148  double accuracyThreshold;
149  double gamma;
150  DistanceType distanceType;
151  bool assignFlag;
153  services::Status check() const DAAL_C11_OVERRIDE;
154 };
155 /* [Parameter source code] */
156 
161 class DAAL_EXPORT InputIface : public daal::algorithms::Input
162 {
163 public:
164  InputIface(size_t nElements) : daal::algorithms::Input(nElements) {};
165 
166  virtual size_t getNumberOfFeatures() const = 0;
167 };
168 
173 class DAAL_EXPORT Input : public InputIface
174 {
175 public:
176  Input();
177  virtual ~Input() {}
178 
184  data_management::NumericTablePtr get(InputId id) const;
185 
191  void set(InputId id, const data_management::NumericTablePtr &ptr);
192 
193 
198  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE;
199 
205  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
206 };
207 
212 class DAAL_EXPORT PartialResult : public daal::algorithms::PartialResult
213 {
214 public:
215  DECLARE_SERIALIZABLE_CAST(PartialResult);
216  PartialResult();
217 
218  virtual ~PartialResult() {};
219 
226  template <typename algorithmFPType>
227  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
228 
234  data_management::NumericTablePtr get(PartialResultId id) const;
235 
241  void set(PartialResultId id, const data_management::NumericTablePtr &ptr);
242 
248  size_t getNumberOfFeatures() const;
249 
256  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
257 
263  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
264 
265 protected:
267  template<typename Archive, bool onDeserialize>
268  services::Status serialImpl(Archive *arch)
269  {
270  return daal::algorithms::PartialResult::serialImpl<Archive, onDeserialize>(arch);
271  }
272 };
273 typedef services::SharedPtr<PartialResult> PartialResultPtr;
274 
279 class DAAL_EXPORT Result : public daal::algorithms::Result
280 {
281 public:
282  DECLARE_SERIALIZABLE_CAST(Result);
283  Result();
284 
285  virtual ~Result() {};
286 
293  template <typename algorithmFPType>
294  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
295 
302  template <typename algorithmFPType>
303  DAAL_EXPORT services::Status allocate(const daal::algorithms::PartialResult *partialResult, const daal::algorithms::Parameter *parameter, const int method);
304 
310  data_management::NumericTablePtr get(ResultId id) const;
311 
317  void set(ResultId id, const data_management::NumericTablePtr &ptr);
318 
325  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
326 
333  services::Status check(const daal::algorithms::PartialResult *pres, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
334 
335 protected:
337  template<typename Archive, bool onDeserialize>
338  services::Status serialImpl(Archive *arch)
339  {
340  return daal::algorithms::Result::serialImpl<Archive, onDeserialize>(arch);
341  }
342 };
343 typedef services::SharedPtr<Result> ResultPtr;
344 
349 class DAAL_EXPORT DistributedStep2MasterInput : public InputIface
350 {
351 public:
352  DistributedStep2MasterInput();
353 
354  virtual ~DistributedStep2MasterInput() {}
355 
361  data_management::DataCollectionPtr get(MasterInputId id) const;
362 
368  void set(MasterInputId id, const data_management::DataCollectionPtr &ptr);
369 
376  void add(MasterInputId id, const PartialResultPtr &value);
377 
383  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE;
384 
390  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
391 };
392 } // namespace interface1
393 using interface1::Parameter;
394 using interface1::InputIface;
395 using interface1::Input;
396 using interface1::PartialResult;
397 using interface1::PartialResultPtr;
398 using interface1::Result;
399 using interface1::ResultPtr;
400 using interface1::DistributedStep2MasterInput;
401 
402 } // namespace daal::algorithms::kmeans
404 } // namespace daal::algorithms
405 } // namespace daal
406 #endif
daal::algorithms::kmeans::interface1::PartialResult
Partial results obtained with the compute() method of K-Means algorithm in the batch processing mode...
Definition: kmeans_types.h:212
daal::algorithms::kmeans::centroids
Definition: kmeans_types.h:109
daal::algorithms::kmeans::interface1::DistributedStep2MasterInput
Input objects for K-Means algorithm in the distributed processing mode
Definition: kmeans_types.h:349
daal::algorithms::kmeans::partialObjectiveFunction
Definition: kmeans_types.h:95
daal::algorithms::kmeans::interface1::Input
Input objects for K-Means algorithm
Definition: kmeans_types.h:173
daal::algorithms::kmeans::interface1::Parameter::maxIterations
size_t maxIterations
Definition: kmeans_types.h:147
daal::algorithms::kmeans::nIterations
Definition: kmeans_types.h:113
daal::algorithms::kmeans::InputId
InputId
Available identifiers of input objects for K-Means algorithm.
Definition: kmeans_types.h:70
daal::algorithms::kmeans::interface1::Parameter
Parameters for K-Means algorithm.
Definition: kmeans_types.h:131
daal::algorithms::kmeans::goalFunction
Definition: kmeans_types.h:112
daal::algorithms::kmeans::interface1::Result
Results obtained with the compute() method of K-Means algorithm in the batch processing mode...
Definition: kmeans_types.h:279
daal::algorithms::kmeans::data
Definition: kmeans_types.h:72
daal::algorithms::kmeans::partialCandidatesDistances
Definition: kmeans_types.h:98
daal::algorithms::kmeans::interface1::InputIface
Interface for input objects for K-Means algorithm in the batch and distributed processing modes...
Definition: kmeans_types.h:161
daal::algorithms::kmeans::interface1::Parameter::assignFlag
bool assignFlag
Definition: kmeans_types.h:151
daal::algorithms::kmeans::lloydDense
Definition: kmeans_types.h:51
daal::algorithms::kmeans::DistanceType
DistanceType
Definition: kmeans_types.h:60
daal::algorithms::kmeans::interface1::Parameter::distanceType
DistanceType distanceType
Definition: kmeans_types.h:150
daal_defines.h
daal::algorithms::kmeans::objectiveFunction
Definition: kmeans_types.h:111
daal::algorithms::kmeans::interface1::Parameter::gamma
double gamma
Definition: kmeans_types.h:149
daal::algorithms::kmeans::partialResults
Definition: kmeans_types.h:83
daal::algorithms::kmeans::PartialResultId
PartialResultId
Available identifiers of partial results of K-Means algorithm in the distributed processing mode...
Definition: kmeans_types.h:91
daal::algorithms::kmeans::lloydCSR
Definition: kmeans_types.h:53
daal::algorithms::kmeans::partialCandidatesCentroids
Definition: kmeans_types.h:99
daal::algorithms::kmeans::nObservations
Definition: kmeans_types.h:93
daal::algorithms::kmeans::Method
Method
Definition: kmeans_types.h:49
daal::algorithms::kmeans::ResultId
ResultId
Available identifiers of results of K-Means algorithm.
Definition: kmeans_types.h:107
daal::algorithms::kmeans::partialAssignments
Definition: kmeans_types.h:97
daal::algorithms::kmeans::inputCentroids
Definition: kmeans_types.h:73
daal::algorithms::kmeans::interface1::Parameter::accuracyThreshold
double accuracyThreshold
Definition: kmeans_types.h:148
daal::algorithms::math::abs::value
Definition: abs_types.h:88
daal::algorithms::kmeans::defaultDense
Definition: kmeans_types.h:52
daal::algorithms::kmeans::partialGoalFunction
Definition: kmeans_types.h:96
daal::algorithms::kmeans::partialSums
Definition: kmeans_types.h:94
daal::algorithms::kmeans::interface1::Parameter::nClusters
size_t nClusters
Definition: kmeans_types.h:146
daal::algorithms::kmeans::assignments
Definition: kmeans_types.h:110
daal::algorithms::kmeans::euclidean
Definition: kmeans_types.h:62
daal::algorithms::kmeans::MasterInputId
MasterInputId
Available identifiers of input objects for K-Means algorithm in the distributed processing mode...
Definition: kmeans_types.h:81

For more complete information about compiler optimizations, see our Optimization Notice.