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

kmeans_init_batch.h
1 /* file: kmeans_init_batch.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 the interface for initializing K-Means algorithm
21 // in the batch processing mode
22 //--
23 */
24 
25 #ifndef __KMEANS_INIT_BATCH_H__
26 #define __KMEANS_INIT_BATCH_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "algorithms/kmeans/kmeans_init_types.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace kmeans
38 {
39 namespace init
40 {
41 
42 namespace interface2
43 {
58 template<typename algorithmFPType, Method method, CpuType cpu>
59 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
60 {
61 public:
67  BatchContainer(daal::services::Environment::env *daalEnv);
69  virtual ~BatchContainer();
73  virtual services::Status compute() DAAL_C11_OVERRIDE;
74 };
75 
76 
81 class DAAL_EXPORT BatchBase : public daal::algorithms::Analysis<batch>
82 {
83 public:
84  typedef algorithms::kmeans::init::Input InputType;
85  typedef algorithms::kmeans::init::Parameter ParameterType;
86  typedef algorithms::kmeans::init::Result ResultType;
87 
89  virtual ~BatchBase() { }
90 
91 protected:
92  BatchBase() { }
93 
94  explicit BatchBase(ParameterType *parameter)
95  {
96  _par = parameter;
97  }
98 };
99 
113 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
114 class DAAL_EXPORT Batch : public BatchBase
115 {
116 public:
121  Batch(size_t nClusters);
122 
129  Batch(const Batch<algorithmFPType, method> &other);
130 
131 
133  ~Batch()
134  {
135  delete _par;
136  }
137 
142  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
143 
148  ResultPtr getResult()
149  {
150  return _result;
151  }
152 
157  services::Status setResult(const ResultPtr& result)
158  {
159  DAAL_CHECK(result, services::ErrorNullResult)
160  _result = result;
161  _res = _result.get();
162  return services::Status();
163  }
164 
170  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
171  {
172  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
173  }
174 
175 protected:
176  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
177  {
178  return new Batch<algorithmFPType, method>(*this);
179  }
180 
181  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
182  {
183  _result.reset(new ResultType());
184  size_t nFeatures = input.getNumberOfFeatures();
185  services::Status s = _result->allocate<algorithmFPType>(_in, _par, (int) method);
186  _res = _result.get();
187  return s;
188  }
189 
190  void initialize()
191  {
192  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
193  _in = &input;
194  }
195 
196 public:
197  ParameterType &parameter;
198  InputType input;
200 private:
201  ResultPtr _result;
202 };
204 } // namespace interface2
205 using interface2::BatchContainer;
206 using interface2::BatchBase;
207 using interface2::Batch;
208 } // namespace daal::algorithms::kmeans::init
209 } // namespace daal::algorithms::kmeans
210 } // namespace daal::algorithms
211 } // namespace daal
212 #endif
daal::batch
Definition: daal_defines.h:112
daal::algorithms::kmeans::init::interface2::BatchBase
Base class representing K-Means algorithm initialization in the batch processing mode.
Definition: kmeans_init_batch.h:81
daal::algorithms::kmeans::init::interface2::BatchContainer
Provides methods to run implementations of initialization of K-Means algorithm. This class is associa...
Definition: kmeans_init_batch.h:59
daal::algorithms::kmeans::init::interface2::Batch::parameter
ParameterType & parameter
Definition: kmeans_init_batch.h:197
daal::algorithms::kmeans::init::interface2::Batch::~Batch
~Batch()
Definition: kmeans_init_batch.h:133
daal::algorithms::kmeans::init::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::kmeans::init::interface2::Batch::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_init_batch.h:157
daal::algorithms::kmeans::init::interface2::BatchBase::~BatchBase
virtual ~BatchBase()
Definition: kmeans_init_batch.h:89
daal::algorithms::kmeans::init::interface2::BatchContainer::~BatchContainer
virtual ~BatchContainer()
daal::algorithms::kmeans::init::interface2::Batch::getResult
ResultPtr getResult()
Definition: kmeans_init_batch.h:148
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::kmeans::init::interface2::BatchContainer::compute
virtual services::Status compute() DAAL_C11_OVERRIDE
daal_defines.h
daal::algorithms::kmeans::init::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_init_batch.h:142
daal::algorithms::kmeans::init::interface2::Batch
Computes initial clusters for K-Means algorithm in the batch processing mode.
Definition: kmeans_init_batch.h:114
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::algorithms::kmeans::init::interface2::Batch::input
InputType input
Definition: kmeans_init_batch.h:198
daal::algorithms::kmeans::init::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: kmeans_init_batch.h:170

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