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

adaboost_training_batch.h
1 /* file: adaboost_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 AdaBoost model-based training in the batch
21 // processing mode
22 //--
23 */
24 
25 #ifndef __ADA_BOOST_TRAINING_BATCH_H__
26 #define __ADA_BOOST_TRAINING_BATCH_H__
27 
28 #include "algorithms/boosting/boosting_training_batch.h"
29 #include "algorithms/boosting/adaboost_training_types.h"
30 #include "algorithms/classifier/classifier_training_batch.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
36 namespace adaboost
37 {
38 namespace training
39 {
40 
41 namespace interface1
42 {
57 template<typename algorithmFPType, Method method, CpuType cpu>
58 class BatchContainer : public TrainingContainerIface<batch>
59 {
60 public:
65  DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv);
67  DAAL_DEPRECATED ~BatchContainer();
71  DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE;
72 };
73 
91 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
92 class DAAL_EXPORT Batch : public boosting::training::Batch
93 {
94 public:
95  typedef boosting::training::Batch super;
96 
97  typedef typename super::InputType InputType;
98  typedef algorithms::adaboost::interface1::Parameter ParameterType;
99  typedef algorithms::adaboost::training::interface1::Result ResultType;
100 
101  ParameterType parameter;
102  InputType input;
104  DAAL_DEPRECATED Batch()
105  {
106  initialize();
107  }
108 
115  DAAL_DEPRECATED Batch(const Batch<algorithmFPType, method> &other) : boosting::training::Batch(other),
116  parameter(other.parameter), input(other.input)
117  {
118  initialize();
119  }
120 
121  DAAL_DEPRECATED_VIRTUAL virtual ~Batch() {}
122 
127  DAAL_DEPRECATED InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
128 
133  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
134 
139  DAAL_DEPRECATED interface1::ResultPtr getResult()
140  {
141  return ResultType::cast(_result);
142  }
143 
147  DAAL_DEPRECATED services::Status resetResult() DAAL_C11_OVERRIDE
148  {
149  _result.reset(new ResultType());
150  DAAL_CHECK(_result, services::ErrorNullResult);
151  _res = NULL;
152  return services::Status();
153  }
154 
160  DAAL_DEPRECATED services::SharedPtr<Batch<algorithmFPType, method> > clone() const
161  {
162  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
163  }
164 
165 protected:
166  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
167  {
168  return new Batch<algorithmFPType, method>(*this);
169  }
170 
171  services::Status allocateResult() DAAL_C11_OVERRIDE
172  {
173  interface1::ResultPtr res = getResult();
174  DAAL_CHECK(res, services::ErrorNullResult);
175  services::Status s = res->template allocate<algorithmFPType>(&input, _par, method);
176  _res = _result.get();
177  return s;
178  }
179 
180  void initialize()
181  {
182  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
183  _in = &input;
184  _par = &parameter;
185  _result.reset(new ResultType());
186  }
187 };
189 } // namespace interface1
190 
191 namespace interface2
192 {
207 template<typename algorithmFPType, Method method, CpuType cpu>
208 class BatchContainer : public TrainingContainerIface<batch>
209 {
210 public:
215  BatchContainer(daal::services::Environment::env *daalEnv);
217  ~BatchContainer();
221  services::Status compute() DAAL_C11_OVERRIDE;
222 };
240 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
241 class DAAL_EXPORT Batch : public classifier::training::Batch
242 {
243 public:
244  typedef classifier::training::Batch super;
245 
246  typedef typename super::InputType InputType;
247  typedef algorithms::adaboost::Parameter ParameterType;
248  typedef algorithms::adaboost::training::Result ResultType;
249 
250  InputType input;
252  Batch(size_t nClasses);
253 
260  Batch(const Batch<algorithmFPType, method> &other);
261 
262  virtual ~Batch()
263  {
264  delete _par;
265  }
266 
271  ParameterType& parameter() { return *static_cast<ParameterType*>(_par); }
272 
277  const ParameterType& parameter() const { return *static_cast<const ParameterType*>(_par); }
278 
283  InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
284 
289  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
290 
295  ResultPtr getResult()
296  {
297  return ResultType::cast(_result);
298  }
299 
303  services::Status resetResult() DAAL_C11_OVERRIDE
304  {
305  _result.reset(new ResultType());
306  DAAL_CHECK(_result, services::ErrorNullResult);
307  _res = NULL;
308  return services::Status();
309  }
310 
316  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
317  {
318  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
319  }
320 
321 protected:
322  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
323  {
324  return new Batch<algorithmFPType, method>(*this);
325  }
326 
327  services::Status allocateResult() DAAL_C11_OVERRIDE
328  {
329  ResultPtr res = getResult();
330  DAAL_CHECK(res, services::ErrorNullResult);
331  services::Status s = res->template allocate<algorithmFPType>(&input, _par, method);
332  _res = _result.get();
333  return s;
334  }
335 
336  void initialize()
337  {
338  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
339  _in = &input;
340  _result.reset(new ResultType());
341  }
342 };
344 } // namespace interface2
345 using interface2::Batch;
346 using interface2::BatchContainer;
347 
348 } // namespace daal::algorithms::adaboost::training
349 }
350 }
351 } // namespace daal
352 #endif // __ADA_BOOST_TRAINING_BATCH_H__
daal::algorithms::adaboost::training::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::adaboost::training::interface1::Batch::input
InputType input
Definition: adaboost_training_batch.h:102
daal::algorithms::adaboost::training::interface1::Batch::getInput
DAAL_DEPRECATED InputType * getInput() DAAL_C11_OVERRIDE
Definition: adaboost_training_batch.h:127
daal::algorithms::adaboost::training::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: adaboost_training_batch.h:289
daal::algorithms::adaboost::training::interface1::Batch::getResult
DAAL_DEPRECATED interface1::ResultPtr getResult()
Definition: adaboost_training_batch.h:139
daal::algorithms::adaboost::training::interface1::BatchContainer
Provides methods to run implementations of AdaBoost model-based training. It is associated with daal:...
Definition: adaboost_training_batch.h:58
daal::batch
Definition: daal_defines.h:112
daal::algorithms::adaboost::training::interface1::Batch
Trains model of the AdaBoost algorithms in batch mode.
Definition: adaboost_training_batch.h:92
daal::algorithms::adaboost::training::interface2::Batch::getResult
ResultPtr getResult()
Definition: adaboost_training_batch.h:295
daal::algorithms::adaboost::training::interface1::BatchContainer::compute
DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::adaboost::training::interface1::Batch::clone
DAAL_DEPRECATED services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: adaboost_training_batch.h:160
daal::algorithms::adaboost::training::interface1::Batch::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: adaboost_training_batch.h:133
daal::algorithms::adaboost::interface1::Parameter
AdaBoost algorithm parameters.
Definition: adaboost_model.h:59
daal::algorithms::adaboost::training::interface1::Result
Provides methods to access final results obtained with the compute() method.
Definition: adaboost_training_types.h:84
daal::algorithms::adaboost::training::interface2::Batch::parameter
const ParameterType & parameter() const
Definition: adaboost_training_batch.h:277
daal::algorithms::adaboost::training::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::adaboost::training::interface2::Batch::input
InputType input
Definition: adaboost_training_batch.h:250
daal::algorithms::adaboost::training::interface2::BatchContainer
Provides methods to run implementations of AdaBoost model-based training. It is associated with daal:...
Definition: adaboost_training_batch.h:208
daal::algorithms::adaboost::training::interface2::Batch
Trains model of the AdaBoost algorithms in batch mode.
Definition: adaboost_training_batch.h:241
daal::algorithms::adaboost::training::interface2::BatchContainer::~BatchContainer
~BatchContainer()
daal::algorithms::adaboost::training::interface1::Batch::resetResult
DAAL_DEPRECATED services::Status resetResult() DAAL_C11_OVERRIDE
Definition: adaboost_training_batch.h:147
daal::algorithms::adaboost::training::interface2::Batch::resetResult
services::Status resetResult() DAAL_C11_OVERRIDE
Definition: adaboost_training_batch.h:303
daal::algorithms::adaboost::training::interface1::BatchContainer::~BatchContainer
DAAL_DEPRECATED ~BatchContainer()
daal::algorithms::adaboost::training::interface2::BatchContainer::compute
services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::adaboost::training::interface2::Batch::parameter
ParameterType & parameter()
Definition: adaboost_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
daal::algorithms::adaboost::training::interface2::Batch::getInput
InputType * getInput() DAAL_C11_OVERRIDE
Definition: adaboost_training_batch.h:283
daal::algorithms::adaboost::training::interface1::Batch::parameter
ParameterType parameter
Definition: adaboost_training_batch.h:101
daal::algorithms::adaboost::training::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: adaboost_training_batch.h:316
daal::algorithms::adaboost::training::interface1::Batch::Batch
DAAL_DEPRECATED Batch(const Batch< algorithmFPType, method > &other)
Definition: adaboost_training_batch.h:115

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