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

svm_model.h
1 /* file: svm_model.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 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 class defining the SVM model.
19 //--
20 */
21 
22 #ifndef __SVM_MODEL_H__
23 #define __SVM_MODEL_H__
24 
25 #include "data_management/data/homogen_numeric_table.h"
26 #include "data_management/data/csr_numeric_table.h"
27 #include "algorithms/model.h"
28 #include "algorithms/kernel_function/kernel_function.h"
29 #include "algorithms/kernel_function/kernel_function_linear.h"
30 #include "algorithms/kernel_function/kernel_function_types.h"
31 #include "algorithms/classifier/classifier_model.h"
32 
33 namespace daal
34 {
35 namespace algorithms
36 {
46 namespace svm
47 {
51 namespace interface1
52 {
63 /* [Parameter source code] */
64 struct DAAL_EXPORT Parameter : public classifier::Parameter
65 {
66  Parameter(const services::SharedPtr<kernel_function::KernelIface> &kernelForParameter
67  = services::SharedPtr<kernel_function::KernelIface>(new kernel_function::linear::Batch<>()),
68  double C = 1.0,
69  double accuracyThreshold = 0.001,
70  double tau = 1.0e-6,
71  size_t maxIterations = 1000000,
72  size_t cacheSize = 8000000,
73  bool doShrinking = true,
74  size_t shrinkingStep = 1000) :
75  C(C), accuracyThreshold(accuracyThreshold), tau(tau), maxIterations(maxIterations), cacheSize(cacheSize),
76  doShrinking(doShrinking), shrinkingStep(shrinkingStep), kernel(kernelForParameter) {};
77 
78  double C;
79  double accuracyThreshold;
80  double tau;
81  size_t maxIterations;
82  size_t cacheSize;
84  bool doShrinking;
85  size_t shrinkingStep;
86  algorithms::kernel_function::KernelIfacePtr kernel;
88  services::Status check() const DAAL_C11_OVERRIDE;
89 };
90 /* [Parameter source code] */
91 
101 class DAAL_EXPORT Model : public classifier::Model
102 {
103 public:
104  DECLARE_MODEL(Model, classifier::Model);
105 
114  template<typename modelFPType>
115  Model(modelFPType dummy, size_t nColumns, data_management::NumericTableIface::StorageLayout layout = data_management::NumericTableIface::aos) :
116  _bias(0.0)
117  {
118  using namespace data_management;
119  if (layout == NumericTableIface::csrArray)
120  {
121  modelFPType *dummyPtr = NULL;
122  _SV.reset(new CSRNumericTable(dummyPtr,NULL,NULL,nColumns));
123  }
124  else
125  {
126  _SV.reset(new HomogenNumericTable<modelFPType>(NULL, nColumns, 0));
127  }
128  _SVCoeff.reset(new HomogenNumericTable<modelFPType>(NULL, 1, 0));
129  _SVIndices.reset(new HomogenNumericTable<int>(NULL, 1, 0));
130  }
131 
140  template<typename modelFPType>
141  DAAL_EXPORT static services::SharedPtr<Model> create(size_t nColumns,
142  data_management::NumericTableIface::StorageLayout layout = data_management::NumericTableIface::aos,
143  services::Status *stat = NULL);
144 
149  Model() : _SV(), _SVIndices(), _SVCoeff(), _bias(0.0) {}
150 
156  static services::SharedPtr<Model> create(services::Status *stat = NULL)
157  {
158  services::SharedPtr<Model> modelPtr(new Model());
159  if (!modelPtr)
160  {
161  if (stat)
162  stat->add(services::ErrorMemoryAllocationFailed);
163  }
164  return modelPtr;
165  }
166 
167  virtual ~Model() {}
168 
173  data_management::NumericTablePtr getSupportVectors() { return _SV; }
174 
179  data_management::NumericTablePtr getSupportIndices() { return _SVIndices; }
180 
185  data_management::NumericTablePtr getClassificationCoefficients() { return _SVCoeff; }
186 
191  virtual double getBias() { return _bias; }
192 
197  virtual void setBias(double bias)
198  {
199  _bias = bias;
200  }
201 
206  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE { return (_SV ? _SV->getNumberOfColumns() : 0); }
207 
208 protected:
209  data_management::NumericTablePtr _SV;
210  data_management::NumericTablePtr _SVCoeff;
211  double _bias;
212  data_management::NumericTablePtr _SVIndices;
214  template<typename modelFPType>
215  DAAL_EXPORT Model(modelFPType dummy, size_t nColumns, data_management::NumericTableIface::StorageLayout layout,
216  services::Status &st);
217 
218  template<typename Archive, bool onDeserialize>
219  services::Status serialImpl(Archive *arch)
220  {
221  services::Status st = classifier::Model::serialImpl<Archive, onDeserialize>(arch);
222  if (!st)
223  return st;
224  arch->setSharedPtrObj(_SV);
225  arch->setSharedPtrObj(_SVCoeff);
226  arch->set(_bias);
227 
228  arch->setSharedPtrObj(_SVIndices);
229 
230  return st;
231  }
232 };
233 typedef services::SharedPtr<Model> ModelPtr;
235 } // namespace interface1
236 using interface1::Parameter;
237 using interface1::Model;
238 using interface1::ModelPtr;
239 
240 } // namespace svm
242 } // namespace algorithms
243 } // namespace daal
244 #endif
daal::algorithms::svm::interface1::Parameter
Optional parameters.
Definition: svm_model.h:64
daal
Definition: algorithm_base_common.h:31
daal::algorithms::svm::interface1::Model::getSupportIndices
data_management::NumericTablePtr getSupportIndices()
Definition: svm_model.h:179
daal::algorithms::svm::interface1::Model
Model of the classifier trained by the svm::training::Batch algorithm
Definition: svm_model.h:101
daal::algorithms::svm::interface1::Model::create
static services::SharedPtr< Model > create(services::Status *stat=NULL)
Definition: svm_model.h:156
daal::algorithms::svm::interface1::Parameter::accuracyThreshold
double accuracyThreshold
Definition: svm_model.h:79
daal::algorithms::svm::interface1::Parameter::shrinkingStep
size_t shrinkingStep
Definition: svm_model.h:85
daal::services::ErrorMemoryAllocationFailed
Definition: error_indexes.h:146
daal::algorithms::svm::interface1::Parameter::tau
double tau
Definition: svm_model.h:80
daal::algorithms::svm::interface1::Model::getBias
virtual double getBias()
Definition: svm_model.h:191
daal::algorithms::svm::interface1::Parameter::doShrinking
bool doShrinking
Definition: svm_model.h:84
daal::algorithms::svm::interface1::Parameter::cacheSize
size_t cacheSize
Definition: svm_model.h:82
daal::algorithms::svm::interface1::Model::Model
Model(modelFPType dummy, size_t nColumns, data_management::NumericTableIface::StorageLayout layout=data_management::NumericTableIface::aos)
Definition: svm_model.h:115
daal::algorithms::svm::interface1::Parameter::kernel
algorithms::kernel_function::KernelIfacePtr kernel
Definition: svm_model.h:86
daal::algorithms::svm::interface1::Model::setBias
virtual void setBias(double bias)
Definition: svm_model.h:197
daal::algorithms::svm::interface1::Model::getClassificationCoefficients
data_management::NumericTablePtr getClassificationCoefficients()
Definition: svm_model.h:185
daal::algorithms::svm::interface1::Model::getSupportVectors
data_management::NumericTablePtr getSupportVectors()
Definition: svm_model.h:173
daal::algorithms::svm::interface1::Model::Model
Model()
Definition: svm_model.h:149
daal::algorithms::svm::interface1::Parameter::maxIterations
size_t maxIterations
Definition: svm_model.h:81
daal::algorithms::svm::interface1::Model::getNumberOfFeatures
size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE
Definition: svm_model.h:206

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