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

kmeans_types.h
1 /* file: kmeans_types.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 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  partialCandidatesDistances,
123  partialCandidatesCentroids,
124  lastPartialResultId = partialCandidatesCentroids
125 };
126 
131 enum ResultId
132 {
133  centroids,
134  assignments,
135  objectiveFunction,
136  goalFunction = objectiveFunction,
137  nIterations,
138  lastResultId = nIterations
139 };
140 
144 namespace interface1
145 {
154 /* [Parameter source code] */
155 struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
156 {
162  Parameter(size_t _nClusters, size_t _maxIterations);
163 
168  Parameter(const Parameter &other);
169 
170  size_t nClusters;
171  size_t maxIterations;
172  double accuracyThreshold;
173  double gamma;
174  DistanceType distanceType;
175  bool assignFlag;
177  services::Status check() const DAAL_C11_OVERRIDE;
178 };
179 /* [Parameter source code] */
180 
185 class DAAL_EXPORT InputIface : public daal::algorithms::Input
186 {
187 public:
188  InputIface(size_t nElements) : daal::algorithms::Input(nElements) {};
189 
190  virtual size_t getNumberOfFeatures() const = 0;
191 };
192 
197 class DAAL_EXPORT Input : public InputIface
198 {
199 public:
200  Input();
201  virtual ~Input() {}
202 
208  data_management::NumericTablePtr get(InputId id) const;
209 
215  void set(InputId id, const data_management::NumericTablePtr &ptr);
216 
217 
222  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE;
223 
229  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
230 };
231 
236 class DAAL_EXPORT PartialResult : public daal::algorithms::PartialResult
237 {
238 public:
239  DECLARE_SERIALIZABLE_CAST(PartialResult);
240  PartialResult();
241 
242  virtual ~PartialResult() {};
243 
250  template <typename algorithmFPType>
251  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
252 
258  data_management::NumericTablePtr get(PartialResultId id) const;
259 
265  void set(PartialResultId id, const data_management::NumericTablePtr &ptr);
266 
272  size_t getNumberOfFeatures() const;
273 
280  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
281 
287  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
288 
289 protected:
291  template<typename Archive, bool onDeserialize>
292  services::Status serialImpl(Archive *arch)
293  {
294  return daal::algorithms::PartialResult::serialImpl<Archive, onDeserialize>(arch);
295  }
296 };
297 typedef services::SharedPtr<PartialResult> PartialResultPtr;
298 
303 class DAAL_EXPORT Result : public daal::algorithms::Result
304 {
305 public:
306  DECLARE_SERIALIZABLE_CAST(Result);
307  Result();
308 
309  virtual ~Result() {};
310 
317  template <typename algorithmFPType>
318  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
319 
326  template <typename algorithmFPType>
327  DAAL_EXPORT services::Status allocate(const daal::algorithms::PartialResult *partialResult, const daal::algorithms::Parameter *parameter, const int method);
328 
334  data_management::NumericTablePtr get(ResultId id) const;
335 
341  void set(ResultId id, const data_management::NumericTablePtr &ptr);
342 
349  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
350 
357  services::Status check(const daal::algorithms::PartialResult *pres, const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
358 
359 protected:
361  template<typename Archive, bool onDeserialize>
362  services::Status serialImpl(Archive *arch)
363  {
364  return daal::algorithms::Result::serialImpl<Archive, onDeserialize>(arch);
365  }
366 };
367 typedef services::SharedPtr<Result> ResultPtr;
368 
373 class DAAL_EXPORT DistributedStep2MasterInput : public InputIface
374 {
375 public:
376  DistributedStep2MasterInput();
377 
378  virtual ~DistributedStep2MasterInput() {}
379 
385  data_management::DataCollectionPtr get(MasterInputId id) const;
386 
392  void set(MasterInputId id, const data_management::DataCollectionPtr &ptr);
393 
400  void add(MasterInputId id, const PartialResultPtr &value);
401 
407  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE;
408 
414  services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
415 };
416 } // namespace interface1
417 using interface1::Parameter;
418 using interface1::InputIface;
419 using interface1::Input;
420 using interface1::PartialResult;
421 using interface1::PartialResultPtr;
422 using interface1::Result;
423 using interface1::ResultPtr;
424 using interface1::DistributedStep2MasterInput;
425 
426 } // namespace daal::algorithms::kmeans
428 } // namespace daal::algorithms
429 } // namespace daal
430 #endif
daal::algorithms::kmeans::interface1::Parameter
Parameters for the K-Means algorithm.
Definition: kmeans_types.h:155
daal::algorithms::kmeans::partialObjectiveFunction
Definition: kmeans_types.h:119
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:303
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
daal
Definition: algorithm_base_common.h:57
daal::algorithms::kmeans::partialCandidatesDistances
Definition: kmeans_types.h:122
daal::algorithms::interface1::Result
Base class to represent final results of the computation. Algorithm-specific final results are repres...
Definition: algorithm_types.h:331
daal::algorithms::kmeans::interface1::Parameter::assignFlag
bool assignFlag
Definition: kmeans_types.h:175
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:185
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:236
daal::algorithms::kmeans::partialCandidatesCentroids
Definition: kmeans_types.h:123
daal::algorithms::kmeans::lloydCSR
Definition: kmeans_types.h:77
daal::algorithms::kmeans::partialAssignments
Definition: kmeans_types.h:121
daal::algorithms::kmeans::data
Definition: kmeans_types.h:96
daal::algorithms::kmeans::interface1::Parameter::accuracyThreshold
double accuracyThreshold
Definition: kmeans_types.h:172
daal::algorithms::kmeans::lloydDense
Definition: kmeans_types.h:75
daal::algorithms::interface1::PartialResult
Base class to represent partial results of the computation. Algorithm-specific partial results are re...
Definition: algorithm_types.h:253
daal::algorithms::kmeans::interface1::Parameter::nClusters
size_t nClusters
Definition: kmeans_types.h:170
daal::algorithms::kmeans::interface1::Parameter::gamma
double gamma
Definition: kmeans_types.h:173
daal::algorithms::kmeans::euclidean
Definition: kmeans_types.h:86
daal::algorithms::kmeans::interface1::DistributedStep2MasterInput
Input objects for the K-Means algorithm in the distributed processing mode
Definition: kmeans_types.h:373
daal::algorithms::kmeans::interface1::Input
Input objects for the K-Means algorithm
Definition: kmeans_types.h:197
daal_defines.h
daal::algorithms::kmeans::goalFunction
Definition: kmeans_types.h:136
daal::algorithms::kmeans::nIterations
Definition: kmeans_types.h:137
daal::algorithms::kmeans::centroids
Definition: kmeans_types.h:133
daal::algorithms::kmeans::partialSums
Definition: kmeans_types.h:118
daal::algorithms::kmeans::objectiveFunction
Definition: kmeans_types.h:135
daal::algorithms::interface1::Parameter
Base class to represent computation parameters. Algorithm-specific parameters are represented as deri...
Definition: algorithm_types.h:86
daal::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::algorithms::kmeans::assignments
Definition: kmeans_types.h:134
daal::algorithms::kmeans::inputCentroids
Definition: kmeans_types.h:97
daal::algorithms::kmeans::partialResults
Definition: kmeans_types.h:107
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::interface1::Parameter::maxIterations
size_t maxIterations
Definition: kmeans_types.h:171
daal::algorithms::kmeans::defaultDense
Definition: kmeans_types.h:76
daal::algorithms::math::abs::value
Definition: abs_types.h:112
daal::algorithms::kmeans::ResultId
ResultId
Available identifiers of results of the K-Means algorithm.
Definition: kmeans_types.h:131
daal::algorithms::kmeans::partialGoalFunction
Definition: kmeans_types.h:120
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::DistanceType
DistanceType
Definition: kmeans_types.h:84
daal::algorithms::kmeans::Method
Method
Definition: kmeans_types.h:73
daal::algorithms::interface1::Input
Base class to represent computation input arguments. Algorithm-specific input arguments are represent...
Definition: algorithm_types.h:217
daal::algorithms::kmeans::nObservations
Definition: kmeans_types.h:117
daal::algorithms::kmeans::InputId
InputId
Available identifiers of input objects for the K-Means algorithm.
Definition: kmeans_types.h:94
daal::algorithms::kmeans::interface1::Parameter::distanceType
DistanceType distanceType
Definition: kmeans_types.h:174

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