C++ API Reference for Intel® Data Analytics Acceleration Library 2019

svm_train.h
1 /* file: svm_train.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the interface for SVM model-based training in the batch
19 // processing mode
20 //--
21 */
22 
23 #ifndef __SVM_TRAIN_H__
24 #define __SVM_TRAIN_H__
25 
26 #include "algorithms/algorithm.h"
27 
28 #include "algorithms/svm/svm_train_types.h"
29 #include "algorithms/classifier/classifier_training_batch.h"
30 
31 namespace daal
32 {
33 namespace algorithms
34 {
35 namespace svm
36 {
37 namespace training
38 {
39 
40 namespace interface1
41 {
54 template<typename algorithmFPType, Method method, CpuType cpu>
55 class DAAL_EXPORT BatchContainer : public TrainingContainerIface<batch>
56 {
57 public:
63  BatchContainer(daal::services::Environment::env *daalEnv);
65  ~BatchContainer();
71  services::Status compute() DAAL_C11_OVERRIDE;
72 };
73 
91 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = boser>
92 class DAAL_EXPORT Batch : public classifier::training::Batch
93 {
94 public:
95  typedef classifier::training::Batch super;
96 
97  typedef typename super::InputType InputType;
98  typedef algorithms::svm::Parameter ParameterType;
99  typedef algorithms::svm::training::Result ResultType;
100 
101  ParameterType parameter;
102  InputType input;
105  Batch()
106  {
107  initialize();
108  };
109 
116  Batch(const Batch<algorithmFPType, method> &other) : classifier::training::Batch(other),
117  parameter(other.parameter), input(other.input)
118  {
119  initialize();
120  }
121 
122  virtual ~Batch() {}
123 
128  InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
129 
134  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
135 
140  ResultPtr getResult()
141  {
142  return ResultType::cast(_result);
143  }
144 
148  services::Status resetResult() DAAL_C11_OVERRIDE
149  {
150  _result.reset(new ResultType());
151  DAAL_CHECK(_result, services::ErrorNullResult);
152  _res = NULL;
153  return services::Status();
154  }
155 
161  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
162  {
163  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
164  }
165 
166 protected:
167  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
168  {
169  return new Batch<algorithmFPType, method>(*this);
170  }
171 
172  services::Status allocateResult() DAAL_C11_OVERRIDE
173  {
174  ResultPtr res = getResult();
175  DAAL_CHECK(res, services::ErrorNullResult);
176  services::Status s = res->template allocate<algorithmFPType>(&input, _par, (int) method);
177  _res = _result.get();
178  return s;
179  }
180 
181  void initialize()
182  {
183  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
184  _in = &input;
185  _par = &parameter;
186  _result.reset(new ResultType());
187  }
188 };
190 } // namespace interface1
191 using interface1::BatchContainer;
192 using interface1::Batch;
193 
194 } // namespace training
195 } // namespace svm
196 } // namespace algorithms
197 } // namespace daal
198 #endif
daal
Definition: algorithm_base_common.h:31
daal::algorithms::svm::training::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: svm_train.h:161
daal::algorithms::svm::training::interface1::Batch::getInput
InputType * getInput() DAAL_C11_OVERRIDE
Definition: svm_train.h:128
daal::algorithms::svm::training::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svm_train.h:134
daal::algorithms::svm::training::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: svm_train.h:116
daal::algorithms::svm::training::interface1::BatchContainer
Class containing methods to compute results of the SVM training.
Definition: svm_train.h:55
daal::batch
Definition: daal_defines.h:106
daal::algorithms::svm::training::interface1::Batch::Batch
Batch()
Definition: svm_train.h:105
daal::algorithms::svm::training::interface1::Batch::getResult
ResultPtr getResult()
Definition: svm_train.h:140
daal::algorithms::svm::training::interface1::Batch::parameter
ParameterType parameter
Definition: svm_train.h:101
daal::algorithms::svm::training::interface1::Batch::resetResult
services::Status resetResult() DAAL_C11_OVERRIDE
Definition: svm_train.h:148
daal::algorithms::svm::training::interface1::Batch
Algorithm class to train the SVM model
Definition: svm_train.h:92
daal::algorithms::svm::training::interface1::Batch::input
InputType input
Definition: svm_train.h:102
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:50

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