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

kmeans_types.h
1 /* file: kmeans_types.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 /*
43 //++
44 // Implementation of the K-Means algorithm interface.
45 //--
46 */
47 
48 #ifndef __KMEANS_TYPES_H__
49 #define __KMEANS_TYPES_H__
50 
51 #include "algorithms/algorithm.h"
52 #include "data_management/data/numeric_table.h"
53 #include "data_management/data/homogen_numeric_table.h"
54 #include "services/daal_defines.h"
55 
56 namespace daal
57 {
58 namespace algorithms
59 {
67 namespace kmeans
68 {
73 enum Method
74 {
75  lloydDense = 0,
76  defaultDense = 0,
77  lloydCSR = 1
78 };
79 
84 enum DistanceType
85 {
86  euclidean,
87  lastDistanceType = euclidean
88 };
89 
94 enum InputId
95 {
96  data,
97  inputCentroids,
98  lastInputId = inputCentroids
99 };
100 
105 enum MasterInputId
106 {
107  partialResults,
108  lastMasterInputId = partialResults
109 };
110 
115 enum PartialResultId
116 {
117  nObservations,
118  partialSums,
119  partialObjectiveFunction,
120  partialGoalFunction = partialObjectiveFunction,
121  partialAssignments,
122  lastPartialResultId = partialAssignments
123 };
124 
129 enum ResultId
130 {
131  centroids,
132  assignments,
133  objectiveFunction,
134  goalFunction = objectiveFunction,
135  nIterations,
136  lastResultId = nIterations
137 };
138 
142 namespace interface1
143 {
152 /* [Parameter source code] */
153 struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
154 {
160  Parameter(size_t _nClusters, size_t _maxIterations);
161 
166  Parameter(const Parameter &other);
167 
168  size_t nClusters;
169  size_t maxIterations;
170  double accuracyThreshold;
171  double gamma;
172  DistanceType distanceType;
173  bool assignFlag;
175  services::Status check() const DAAL_C11_OVERRIDE;
176 };
177 /* [Parameter source code] */
178 
183 class DAAL_EXPORT InputIface : public daal::algorithms::Input
184 {
185 public:
186  InputIface(size_t nElements) : daal::algorithms::Input(nElements) {};
187 
188  virtual size_t getNumberOfFeatures() const = 0;
189 };
190 
195 class DAAL_EXPORT Input : public InputIface
196 {
197 public:
198  Input();
199  virtual ~Input() {}
200 
206  data_management::NumericTablePtr get(InputId id) const;
207 
213  void set(InputId id, const data_management::NumericTablePtr &ptr);
214 
215 
220  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE;
221 
227  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
228 };
229 
234 class DAAL_EXPORT PartialResult : public daal::algorithms::PartialResult
235 {
236 public:
237  DECLARE_SERIALIZABLE_CAST(PartialResult);
238  PartialResult();
239 
240  virtual ~PartialResult() {};
241 
248  template <typename algorithmFPType>
249  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
250 
256  data_management::NumericTablePtr get(PartialResultId id) const;
257 
263  void set(PartialResultId id, const data_management::NumericTablePtr &ptr);
264 
270  size_t getNumberOfFeatures() const;
271 
278  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
279 
285  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
286 
287 protected:
289  template<typename Archive, bool onDeserialize>
290  services::Status serialImpl(Archive *arch)
291  {
292  return daal::algorithms::PartialResult::serialImpl<Archive, onDeserialize>(arch);
293  }
294 };
295 typedef services::SharedPtr<PartialResult> PartialResultPtr;
296 
301 class DAAL_EXPORT Result : public daal::algorithms::Result
302 {
303 public:
304  DECLARE_SERIALIZABLE_CAST(Result);
305  Result();
306 
307  virtual ~Result() {};
308 
315  template <typename algorithmFPType>
316  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
317 
324  template <typename algorithmFPType>
325  DAAL_EXPORT services::Status allocate(const daal::algorithms::PartialResult *partialResult, const daal::algorithms::Parameter *parameter, const int method);
326 
332  data_management::NumericTablePtr get(ResultId id) const;
333 
339  void set(ResultId id, const data_management::NumericTablePtr &ptr);
340 
347  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
348 
355  services::Status check(const daal::algorithms::PartialResult *pres, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
356 
357 protected:
359  template<typename Archive, bool onDeserialize>
360  services::Status serialImpl(Archive *arch)
361  {
362  return daal::algorithms::Result::serialImpl<Archive, onDeserialize>(arch);
363  }
364 };
365 typedef services::SharedPtr<Result> ResultPtr;
366 
371 class DAAL_EXPORT DistributedStep2MasterInput : public InputIface
372 {
373 public:
374  DistributedStep2MasterInput();
375 
376  virtual ~DistributedStep2MasterInput() {}
377 
383  data_management::DataCollectionPtr get(MasterInputId id) const;
384 
390  void set(MasterInputId id, const data_management::DataCollectionPtr &ptr);
391 
398  void add(MasterInputId id, const PartialResultPtr &value);
399 
405  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE;
406 
412  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
413 };
414 } // namespace interface1
415 using interface1::Parameter;
416 using interface1::InputIface;
417 using interface1::Input;
418 using interface1::PartialResult;
419 using interface1::PartialResultPtr;
420 using interface1::Result;
421 using interface1::ResultPtr;
422 using interface1::DistributedStep2MasterInput;
423 
424 } // namespace daal::algorithms::kmeans
426 } // namespace daal::algorithms
427 } // namespace daal
428 #endif
daal::algorithms::kmeans::partialAssignments
Definition: kmeans_types.h:121
daal::algorithms::kmeans::interface1::Parameter
Parameters for the K-Means algorithm.
Definition: kmeans_types.h:153
daal::algorithms::kmeans::interface1::Result
Results obtained with the compute() method of the K-Means algorithm in the batch processing mode...
Definition: kmeans_types.h:301
daal
Definition: algorithm_base_common.h:57
daal::algorithms::kmeans::interface1::Parameter::assignFlag
bool assignFlag
Definition: kmeans_types.h:173
daal::algorithms::kmeans::interface1::InputIface
Interface for input objects for the the K-Means algorithm in the batch and distributed processing mod...
Definition: kmeans_types.h:183
daal::algorithms::kmeans::interface1::PartialResult
Partial results obtained with the compute() method of the K-Means algorithm in the batch processing m...
Definition: kmeans_types.h:234
daal::algorithms::kmeans::lloydCSR
Definition: kmeans_types.h:77
daal::algorithms::kmeans::MasterInputId
MasterInputId
Available identifiers of input objects for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_types.h:105
daal::algorithms::kmeans::PartialResultId
PartialResultId
Available identifiers of partial results of the K-Means algorithm in the distributed processing mode...
Definition: kmeans_types.h:115
daal::algorithms::kmeans::assignments
Definition: kmeans_types.h:132
daal::algorithms::kmeans::interface1::Parameter::accuracyThreshold
double accuracyThreshold
Definition: kmeans_types.h:170
daal::algorithms::kmeans::nIterations
Definition: kmeans_types.h:135
daal::algorithms::kmeans::interface1::Parameter::nClusters
size_t nClusters
Definition: kmeans_types.h:168
daal::algorithms::kmeans::interface1::Parameter::gamma
double gamma
Definition: kmeans_types.h:171
daal::algorithms::kmeans::inputCentroids
Definition: kmeans_types.h:97
daal::algorithms::kmeans::partialObjectiveFunction
Definition: kmeans_types.h:119
daal::algorithms::kmeans::interface1::DistributedStep2MasterInput
Input objects for the K-Means algorithm in the distributed processing mode
Definition: kmeans_types.h:371
daal::algorithms::kmeans::interface1::Input
Input objects for the K-Means algorithm
Definition: kmeans_types.h:195
daal_defines.h
daal::algorithms::kmeans::lloydDense
Definition: kmeans_types.h:75
daal::algorithms::kmeans::data
Definition: kmeans_types.h:96
daal::algorithms::kmeans::defaultDense
Definition: kmeans_types.h:76
daal::algorithms::kmeans::InputId
InputId
Available identifiers of input objects for the K-Means algorithm.
Definition: kmeans_types.h:94
daal::algorithms::kmeans::nObservations
Definition: kmeans_types.h:117
daal::algorithms::kmeans::ResultId
ResultId
Available identifiers of results of the K-Means algorithm.
Definition: kmeans_types.h:129
daal::algorithms::kmeans::goalFunction
Definition: kmeans_types.h:134
daal::algorithms::kmeans::partialGoalFunction
Definition: kmeans_types.h:120
daal::algorithms::kmeans::interface1::Parameter::maxIterations
size_t maxIterations
Definition: kmeans_types.h:169
daal::algorithms::kmeans::DistanceType
DistanceType
Definition: kmeans_types.h:84
daal::algorithms::kmeans::partialResults
Definition: kmeans_types.h:107
daal::algorithms::math::abs::value
Definition: abs_types.h:112
daal::algorithms::kmeans::Method
Method
Definition: kmeans_types.h:73
daal::algorithms::kmeans::euclidean
Definition: kmeans_types.h:86
daal::algorithms::kmeans::partialSums
Definition: kmeans_types.h:118
daal::algorithms::kmeans::objectiveFunction
Definition: kmeans_types.h:133
daal::algorithms::kmeans::interface1::Parameter::distanceType
DistanceType distanceType
Definition: kmeans_types.h:172
daal::algorithms::kmeans::centroids
Definition: kmeans_types.h:131

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