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

kmeans_batch.h
1 /* file: kmeans_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 K-Means algorithm in the batch
21 // processing mode
22 //--
23 */
24 
25 #ifndef __KMEANS_BATCH_H__
26 #define __KMEANS_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_types.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace kmeans
38 {
39 
40 namespace interface1
41 {
56 template<typename algorithmFPType, Method method, CpuType cpu>
57 class 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 = lloydDense>
88 class DAAL_EXPORT Batch : public daal::algorithms::Analysis<batch>
89 {
90 public:
91  typedef algorithms::kmeans::Input InputType;
92  typedef algorithms::kmeans::Parameter ParameterType;
93  typedef algorithms::kmeans::Result ResultType;
94 
100  Batch(size_t nClusters, size_t nIterations = 1) : parameter(nClusters, nIterations)
101  {
102  initialize();
103  }
104 
111  Batch(const Batch<algorithmFPType, method> &other) : parameter(other.parameter)
112  {
113  initialize();
114  input.set(data, other.input.get(data));
115  input.set(inputCentroids, other.input.get(inputCentroids));
116  }
117 
122  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
123 
128  ResultPtr getResult()
129  {
130  return _result;
131  }
132 
137  services::Status setResult(const ResultPtr& result)
138  {
139  DAAL_CHECK(result, services::ErrorNullResult)
140  _result = result;
141  _res = _result.get();
142  return services::Status();
143  }
144 
150  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
151  {
152  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
153  }
154 
155 protected:
156  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
157  {
158  return new Batch<algorithmFPType, method>(*this);
159  }
160 
161  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
162  {
163  _result.reset(new ResultType());
164  services::Status s = _result->allocate<algorithmFPType>(_in, _par, (int) method);
165  _res = _result.get();
166  return s;
167  }
168 
169  void initialize()
170  {
171  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
172  _in = &input;
173  _par = &parameter;
174  }
175 
176 public:
177  InputType input;
178  ParameterType parameter;
180 private:
181  ResultPtr _result;
182 };
184 } // namespace interface1
185 using interface1::BatchContainer;
186 using interface1::Batch;
187 
188 } // namespace daal::algorithms::kmeans
189 } // namespace daal::algorithms
190 } // namespace daal
191 #endif
daal::batch
Definition: daal_defines.h:112
daal::algorithms::kmeans::nIterations
Definition: kmeans_types.h:113
daal::algorithms::kmeans::data
Definition: kmeans_types.h:72
daal::algorithms::kmeans::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kmeans_batch.h:122
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_defines.h
daal::algorithms::kmeans::interface1::Batch
Computes the results of K-Means algorithm in the batch processing mode.
Definition: kmeans_batch.h:88
daal::algorithms::kmeans::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: kmeans_batch.h:111
daal::algorithms::kmeans::interface1::Batch::Batch
Batch(size_t nClusters, size_t nIterations=1)
Definition: kmeans_batch.h:100
daal::algorithms::kmeans::interface1::Batch::input
InputType input
Definition: kmeans_batch.h:177
daal::algorithms::kmeans::interface1::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::kmeans::interface1::Batch::getResult
ResultPtr getResult()
Definition: kmeans_batch.h:128
daal::algorithms::kmeans::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: kmeans_batch.h:150
daal::algorithms::kmeans::interface1::BatchContainer::compute
virtual services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::kmeans::interface1::Batch::parameter
ParameterType parameter
Definition: kmeans_batch.h:178
daal::algorithms::kmeans::inputCentroids
Definition: kmeans_types.h:73
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::interface1::Batch::setResult
services::Status setResult(const ResultPtr &result)
Definition: kmeans_batch.h:137
daal::algorithms::kmeans::interface1::BatchContainer
Provides methods to run implementations of K-Means algorithm. This class is associated with the daal:...
Definition: kmeans_batch.h:57
daal::algorithms::kmeans::interface1::BatchContainer::~BatchContainer
virtual ~BatchContainer()

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