C++ API Reference for Intel® Data Analytics Acceleration Library 2019

kmeans_init_batch.h
1 /* file: kmeans_init_batch.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the interface for initializing the K-Means algorithm
19 // in the batch processing mode
20 //--
21 */
22 
23 #ifndef __KMEANS_INIT_BATCH_H__
24 #define __KMEANS_INIT_BATCH_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "algorithms/kmeans/kmeans_init_types.h"
30 
31 namespace daal
32 {
33 namespace algorithms
34 {
35 namespace kmeans
36 {
37 namespace init
38 {
39 
40 namespace interface1
41 {
56 template<typename algorithmFPType, Method method, CpuType cpu>
57 class DAAL_EXPORT BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
58 {
59 public:
65  BatchContainer(daal::services::Environment::env *daalEnv);
67  virtual ~BatchContainer();
71  virtual services::Status compute() DAAL_C11_OVERRIDE;
72 };
73 
87 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
88 class DAAL_EXPORT Batch : public daal::algorithms::Analysis<batch>
89 {
90 public:
91  typedef algorithms::kmeans::init::Input InputType;
92  typedef algorithms::kmeans::init::Parameter ParameterType;
93  typedef algorithms::kmeans::init::Result ResultType;
94 
99  Batch(size_t nClusters) : parameter(nClusters)
100  {
101  initialize();
102  }
103 
110  Batch(const Batch<algorithmFPType, method> &other) : parameter(other.parameter)
111  {
112  initialize();
113  input.set(data, other.input.get(data));
114  }
115 
120  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
121 
126  ResultPtr getResult()
127  {
128  return _result;
129  }
130 
135  services::Status setResult(const ResultPtr& result)
136  {
137  DAAL_CHECK(result, services::ErrorNullResult)
138  _result = result;
139  _res = _result.get();
140  return services::Status();
141  }
142 
148  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
149  {
150  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
151  }
152 
153 protected:
154  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
155  {
156  return new Batch<algorithmFPType, method>(*this);
157  }
158 
159  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
160  {
161  _result.reset(new ResultType());
162  size_t nFeatures = input.getNumberOfFeatures();
163  services::Status s = _result->allocate<algorithmFPType>(_in, _par, (int) method);
164  _res = _result.get();
165  return s;
166  }
167 
168  void initialize()
169  {
170  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
171  _in = &input;
172  _par = &parameter;
173  }
174 
175 public:
176  InputType input;
177  ParameterType parameter;
179 private:
180  ResultPtr _result;
181 };
183 } // namespace interface1
184 using interface1::BatchContainer;
185 using interface1::Batch;
186 } // namespace daal::algorithms::kmeans::init
187 } // namespace daal::algorithms::kmeans
188 } // namespace daal::algorithms
189 } // namespace daal
190 #endif
daal::algorithms::kmeans::init::data
Definition: kmeans_init_types.h:83
daal
Definition: algorithm_base_common.h:31
daal::algorithms::kmeans::init::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_init_batch.h:120
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:53
daal::algorithms::kmeans::init::interface1::Batch
Computes initial clusters for the K-Means algorithm in the batch processing mode. ...
Definition: kmeans_init_batch.h:88
daal::algorithms::kmeans::init::interface1::Batch::parameter
ParameterType parameter
Definition: kmeans_init_batch.h:177
daal::algorithms::kmeans::init::interface1::Batch::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_init_batch.h:135
daal_defines.h
daal::batch
Definition: daal_defines.h:106
daal::algorithms::kmeans::init::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: kmeans_init_batch.h:110
daal::algorithms::kmeans::init::interface1::Batch::getResult
ResultPtr getResult()
Definition: kmeans_init_batch.h:126
daal::algorithms::kmeans::init::interface1::Batch::Batch
Batch(size_t nClusters)
Definition: kmeans_init_batch.h:99
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::kmeans::init::interface1::BatchContainer
Provides methods to run implementations of initialization of the K-Means algorithm. This class is associated with the daal::algorithms::kmeans::init::Batch class and supports the method of computing initial clusters for the K-Means algorithm in the batch processing mode.
Definition: kmeans_init_batch.h:57
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::kmeans::init::interface1::Batch::input
InputType input
Definition: kmeans_init_batch.h:176
daal::algorithms::kmeans::init::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: kmeans_init_batch.h:148

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