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

svm_train.h
1 /* file: svm_train.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 SVM model-based training in the batch
21 // processing mode
22 //--
23 */
24 
25 #ifndef __SVM_TRAIN_H__
26 #define __SVM_TRAIN_H__
27 
28 #include "algorithms/algorithm.h"
29 
30 #include "algorithms/svm/svm_train_types.h"
31 #include "algorithms/classifier/classifier_training_batch.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
37 namespace svm
38 {
39 namespace training
40 {
41 
42 namespace interface1
43 {
56 template<typename algorithmFPType, Method method, CpuType cpu>
57 class BatchContainer : public TrainingContainerIface<batch>
58 {
59 public:
65  BatchContainer(daal::services::Environment::env *daalEnv);
67  ~BatchContainer();
73  services::Status compute() DAAL_C11_OVERRIDE;
74 };
75 
93 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = boser>
94 class DAAL_EXPORT Batch : public classifier::training::interface1::Batch
95 {
96 public:
97  typedef classifier::training::interface1::Batch super;
98 
99  typedef typename super::InputType InputType;
100  typedef algorithms::svm::interface1::Parameter ParameterType;
101  typedef algorithms::svm::training::Result ResultType;
102 
103  ParameterType parameter;
104  InputType input;
107  Batch()
108  {
109  initialize();
110  };
111 
118  Batch(const Batch<algorithmFPType, method> &other) : classifier::training::interface1::Batch(other),
119  parameter(other.parameter), input(other.input)
120  {
121  initialize();
122  }
123 
124  virtual ~Batch() {}
125 
130  InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
131 
136  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
137 
142  interface1::ResultPtr getResult()
143  {
144  return ResultType::cast(_result);
145  }
146 
150  services::Status resetResult() DAAL_C11_OVERRIDE
151  {
152  _result.reset(new ResultType());
153  DAAL_CHECK(_result, services::ErrorNullResult);
154  _res = NULL;
155  return services::Status();
156  }
157 
163  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
164  {
165  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
166  }
167 
168 protected:
169  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
170  {
171  return new Batch<algorithmFPType, method>(*this);
172  }
173 
174  services::Status allocateResult() DAAL_C11_OVERRIDE
175  {
176  ResultPtr res = getResult();
177  DAAL_CHECK(res, services::ErrorNullResult);
178  services::Status s = res->template allocate<algorithmFPType>(&input, _par, (int) method);
179  _res = _result.get();
180  return s;
181  }
182 
183  void initialize()
184  {
185  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
186  _in = &input;
187  _par = &parameter;
188  _result.reset(new ResultType());
189  }
190 };
192 } // namespace interface1
193 
194 namespace interface2
195 {
208 template<typename algorithmFPType, Method method, CpuType cpu>
209 class BatchContainer : public TrainingContainerIface<batch>
210 {
211 public:
217  BatchContainer(daal::services::Environment::env *daalEnv);
219  ~BatchContainer();
225  services::Status compute() DAAL_C11_OVERRIDE;
226 };
227 
245 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = boser>
246 class DAAL_EXPORT Batch : public classifier::training::Batch
247 {
248 public:
249  typedef classifier::training::Batch super;
250 
251  typedef typename super::InputType InputType;
252  typedef algorithms::svm::Parameter ParameterType;
253  typedef algorithms::svm::training::Result ResultType;
254 
255  ParameterType parameter;
256  InputType input;
259  Batch()
260  {
261  initialize();
262  };
263 
270  Batch(const Batch<algorithmFPType, method> &other) : classifier::training::Batch(other),
271  parameter(other.parameter), input(other.input)
272  {
273  initialize();
274  }
275 
276  virtual ~Batch() {}
277 
282  InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
283 
288  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
289 
294  ResultPtr getResult()
295  {
296  return ResultType::cast(_result);
297  }
298 
302  services::Status resetResult() DAAL_C11_OVERRIDE
303  {
304  _result.reset(new ResultType());
305  DAAL_CHECK(_result, services::ErrorNullResult);
306  _res = NULL;
307  return services::Status();
308  }
309 
315  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
316  {
317  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
318  }
319 
320 protected:
321  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
322  {
323  return new Batch<algorithmFPType, method>(*this);
324  }
325 
326  services::Status allocateResult() DAAL_C11_OVERRIDE
327  {
328  ResultPtr res = getResult();
329  DAAL_CHECK(res, services::ErrorNullResult);
330  services::Status s = res->template allocate<algorithmFPType>(&input, _par, (int) method);
331  _res = _result.get();
332  return s;
333  }
334 
335  void initialize()
336  {
337  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
338  _in = &input;
339  _par = &parameter;
340  _result.reset(new ResultType());
341  }
342 };
344 } // namespace interface2
345 using interface2::BatchContainer;
346 using interface2::Batch;
347 
348 } // namespace training
349 } // namespace svm
350 } // namespace algorithms
351 } // namespace daal
352 #endif
daal::algorithms::svm::training::interface2::Batch::Batch
Batch()
Definition: svm_train.h:259
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::svm::training::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: svm_train.h:270
daal::algorithms::svm::training::interface2::Batch::getInput
InputType * getInput() DAAL_C11_OVERRIDE
Definition: svm_train.h:282
daal::algorithms::svm::training::interface1::BatchContainer::~BatchContainer
~BatchContainer()
daal::batch
Definition: daal_defines.h:112
daal::algorithms::svm::training::interface2::BatchContainer::~BatchContainer
~BatchContainer()
daal::algorithms::classifier::training::interface1::Batch
Algorithm class for training the classifier model.
Definition: classifier_training_batch.h:58
daal::algorithms::svm::training::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svm_train.h:288
daal::algorithms::svm::training::interface2::Batch
Algorithm class to train the SVM model
Definition: svm_train.h:246
daal::algorithms::svm::training::interface1::Batch::resetResult
services::Status resetResult() DAAL_C11_OVERRIDE
Definition: svm_train.h:150
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::svm::training::interface1::Batch::getInput
InputType * getInput() DAAL_C11_OVERRIDE
Definition: svm_train.h:130
daal::algorithms::svm::training::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svm_train.h:136
daal::algorithms::svm::training::interface2::Batch::getResult
ResultPtr getResult()
Definition: svm_train.h:294
daal::algorithms::svm::training::interface1::Batch::input
InputType input
Definition: svm_train.h:104
daal::algorithms::svm::training::interface2::BatchContainer::compute
services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::svm::training::interface1::Batch::Batch
Batch()
Definition: svm_train.h:107
daal::algorithms::svm::training::interface1::BatchContainer::compute
services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::svm::training::interface2::BatchContainer
Class containing methods to compute results of the SVM training.
Definition: svm_train.h:209
daal::algorithms::classifier::interface1::Parameter
Base class for the parameters of the classification algorithm.
Definition: classifier_model.h:69
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::svm::training::interface2::Batch::input
InputType input
Definition: svm_train.h:256
daal::algorithms::svm::training::interface1::BatchContainer
Class containing methods to compute results of the SVM training.
Definition: svm_train.h:57
daal::algorithms::svm::interface1::Parameter
Optional parameters.
Definition: svm_model.h:66
daal::algorithms::svm::training::interface1::Batch::parameter
ParameterType parameter
Definition: svm_train.h:103
daal::algorithms::svm::training::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: svm_train.h:163
daal::algorithms::svm::training::interface1::Batch
Algorithm class to train the SVM model
Definition: svm_train.h:94
daal::algorithms::svm::training::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: svm_train.h:118
daal::algorithms::svm::training::interface1::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::svm::training::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: svm_train.h:315
daal::algorithms::svm::training::interface2::Batch::parameter
ParameterType parameter
Definition: svm_train.h:255
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52
daal::algorithms::svm::training::interface1::Batch::getResult
interface1::ResultPtr getResult()
Definition: svm_train.h:142
daal::algorithms::svm::training::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::svm::training::interface2::Batch::resetResult
services::Status resetResult() DAAL_C11_OVERRIDE
Definition: svm_train.h:302

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