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

kdtree_knn_classification_training_batch.h
1 /* file: kdtree_knn_classification_training_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-Nearest Neighbor (kNN) model-based training in the batch processing mode
21 //--
22 */
23 
24 #ifndef __KDTREE_KNN_CLASSIFICATION_TRAINING_BATCH_H__
25 #define __KDTREE_KNN_CLASSIFICATION_TRAINING_BATCH_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "algorithms/k_nearest_neighbors/kdtree_knn_classification_training_types.h"
29 #include "algorithms/k_nearest_neighbors/kdtree_knn_classification_model.h"
30 #include "algorithms/classifier/classifier_training_batch.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
36 namespace kdtree_knn_classification
37 {
38 namespace training
39 {
40 namespace interface1
41 {
52 template <typename algorithmFPType, Method method, CpuType cpu>
53 class BatchContainer : public TrainingContainerIface<batch>
54 {
55 public:
60  DAAL_DEPRECATED BatchContainer(daal::services::Environment::env * daalEnv);
61 
63  DAAL_DEPRECATED ~BatchContainer();
64 
68  DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE;
69 };
70 
86 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
87 class DAAL_EXPORT Batch : public classifier::training::interface1::Batch
88 {
89 public:
90  typedef classifier::training::interface1::Batch super;
91 
92  typedef typename super::InputType InputType;
93  typedef algorithms::kdtree_knn_classification::interface1::Parameter ParameterType;
94  typedef algorithms::kdtree_knn_classification::training::Result ResultType;
95 
96  ParameterType parameter;
97  InputType input;
100  DAAL_DEPRECATED Batch()
101  {
102  initialize();
103  }
104 
111  DAAL_DEPRECATED Batch(const Batch<algorithmFPType, method> & other) : classifier::training::interface1::Batch(other),
112  parameter(other.parameter), input(other.input)
113  {
114  initialize();
115  }
116 
121  DAAL_DEPRECATED InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
122 
127  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
128 
133  DAAL_DEPRECATED interface1::ResultPtr getResult() { return Result::cast(_result); }
134 
138  DAAL_DEPRECATED services::Status resetResult() DAAL_C11_OVERRIDE
139  {
140  _result.reset(new ResultType());
141  DAAL_CHECK(_result, services::ErrorNullResult);
142  _res = NULL;
143  return services::Status();
144  }
145 
152  DAAL_DEPRECATED services::SharedPtr<Batch<algorithmFPType, method> > clone() const
153  {
154  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
155  }
156 
157 protected:
158  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
159  {
160  return new Batch<algorithmFPType, method>(*this);
161  }
162 
163  services::Status allocateResult() DAAL_C11_OVERRIDE
164  {
165  const interface1::ResultPtr res = getResult();
166  DAAL_CHECK(_result, services::ErrorNullResult);
167  services::Status s = res->template allocate<algorithmFPType>((classifier::training::InputIface *)(&input), &parameter, (int)method);
168  _res = _result.get();
169  return s;
170  }
171 
172  void initialize()
173  {
174  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
175  _in = &input;
176  _par = &parameter;
177  _result.reset(new ResultType());
178  }
179 };
180 
182 } // namespace interface1
183 
184 namespace interface2
185 {
196 template <typename algorithmFPType, Method method, CpuType cpu>
197 class BatchContainer : public TrainingContainerIface<batch>
198 {
199 public:
204  BatchContainer(daal::services::Environment::env * daalEnv);
205 
207  ~BatchContainer();
208 
212  services::Status compute() DAAL_C11_OVERRIDE;
213 };
214 
230 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
231 class DAAL_EXPORT Batch : public classifier::training::Batch
232 {
233 public:
234  typedef classifier::training::Batch super;
235 
236  typedef typename super::InputType InputType;
237  typedef algorithms::kdtree_knn_classification::Parameter ParameterType;
238  typedef algorithms::kdtree_knn_classification::training::Result ResultType;
239 
240  ParameterType parameter;
241  InputType input;
244  Batch()
245  {
246  initialize();
247  }
248 
255  Batch(const Batch<algorithmFPType, method> & other) : classifier::training::Batch(other),
256  parameter(other.parameter), input(other.input)
257  {
258  initialize();
259  }
260 
265  InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
266 
271  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
272 
277  ResultPtr getResult() { return Result::cast(_result); }
278 
282  services::Status resetResult() DAAL_C11_OVERRIDE
283  {
284  _result.reset(new ResultType());
285  DAAL_CHECK(_result, services::ErrorNullResult);
286  _res = NULL;
287  return services::Status();
288  }
289 
296  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
297  {
298  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
299  }
300 
301 protected:
302  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
303  {
304  return new Batch<algorithmFPType, method>(*this);
305  }
306 
307  services::Status allocateResult() DAAL_C11_OVERRIDE
308  {
309  const ResultPtr res = getResult();
310  DAAL_CHECK(_result, services::ErrorNullResult);
311  services::Status s = res->template allocate<algorithmFPType>((classifier::training::InputIface *)(&input), &parameter, (int)method);
312  _res = _result.get();
313  return s;
314  }
315 
316  void initialize()
317  {
318  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
319  _in = &input;
320  _par = &parameter;
321  _result.reset(new ResultType());
322  }
323 };
324 
326 } // namespace interface2
327 
328 using interface2::BatchContainer;
329 using interface2::Batch;
330 
331 } // namespace training
332 } // namespace kdtree_knn_classification
333 } // namespace algorithms
334 } // namespace daal
335 
336 #endif
daal::algorithms::kdtree_knn_classification::training::interface2::BatchContainer::~BatchContainer
~BatchContainer()
daal::algorithms::kdtree_knn_classification::training::interface1::BatchContainer::compute
DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::classifier::training::interface1::Result
Provides methods to access final results obtained with the compute() method in the batch processing m...
Definition: classifier_training_types.h:198
daal::algorithms::kdtree_knn_classification::training::interface2::BatchContainer::compute
services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::kdtree_knn_classification::training::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::kdtree_knn_classification::training::interface1::Batch
Provides methods for KD-tree based kNN model-based training in the batch processing mode...
Definition: kdtree_knn_classification_training_batch.h:87
daal::batch
Definition: daal_defines.h:112
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::input
InputType input
Definition: kdtree_knn_classification_training_batch.h:241
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::Batch
Batch()
Definition: kdtree_knn_classification_training_batch.h:244
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: kdtree_knn_classification_training_batch.h:127
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::getResult
ResultPtr getResult()
Definition: kdtree_knn_classification_training_batch.h:277
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: kdtree_knn_classification_training_batch.h:296
daal::algorithms::kdtree_knn_classification::training::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::kdtree_knn_classification::interface1::Parameter
KD-tree based kNN algorithm parameters.
Definition: kdtree_knn_classification_model.h:74
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::parameter
ParameterType parameter
Definition: kdtree_knn_classification_training_batch.h:240
daal::algorithms::classifier::training::interface1::Batch
Algorithm class for training the classifier model.
Definition: classifier_training_batch.h:58
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: kdtree_knn_classification_training_batch.h:255
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::getInput
InputType * getInput() DAAL_C11_OVERRIDE
Definition: kdtree_knn_classification_training_batch.h:265
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::resetResult
DAAL_DEPRECATED services::Status resetResult() DAAL_C11_OVERRIDE
Definition: kdtree_knn_classification_training_batch.h:138
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::Batch
DAAL_DEPRECATED Batch(const Batch< algorithmFPType, method > &other)
Definition: kdtree_knn_classification_training_batch.h:111
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::resetResult
services::Status resetResult() DAAL_C11_OVERRIDE
Definition: kdtree_knn_classification_training_batch.h:282
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::Batch
DAAL_DEPRECATED Batch()
Definition: kdtree_knn_classification_training_batch.h:100
daal::algorithms::kdtree_knn_classification::training::interface1::BatchContainer::~BatchContainer
DAAL_DEPRECATED ~BatchContainer()
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::parameter
ParameterType parameter
Definition: kdtree_knn_classification_training_batch.h:96
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::getInput
DAAL_DEPRECATED InputType * getInput() DAAL_C11_OVERRIDE
Definition: kdtree_knn_classification_training_batch.h:121
daal::algorithms::classifier::interface1::Parameter
Base class for the parameters of the classification algorithm.
Definition: classifier_model.h:69
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::input
InputType input
Definition: kdtree_knn_classification_training_batch.h:97
daal::algorithms::classifier::training::interface1::Input
Base class for the input objects in the training stage of the classification algorithms.
Definition: classifier_training_types.h:110
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::getResult
DAAL_DEPRECATED interface1::ResultPtr getResult()
Definition: kdtree_knn_classification_training_batch.h:133
daal::algorithms::kdtree_knn_classification::training::interface2::BatchContainer
Class containing methods for KD-tree based kNN model-based training using algorithmFPType precision a...
Definition: kdtree_knn_classification_training_batch.h:197
daal::algorithms::kdtree_knn_classification::training::interface2::Batch
Provides methods for KD-tree based kNN model-based training in the batch processing mode...
Definition: kdtree_knn_classification_training_batch.h:231
daal::algorithms::kdtree_knn_classification::training::interface1::Batch::clone
DAAL_DEPRECATED services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: kdtree_knn_classification_training_batch.h:152
daal::algorithms::kdtree_knn_classification::training::interface1::BatchContainer
Class containing methods for KD-tree based kNN model-based training using algorithmFPType precision a...
Definition: kdtree_knn_classification_training_batch.h:53
daal::algorithms::kdtree_knn_classification::training::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: kdtree_knn_classification_training_batch.h:271
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52

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