C++ API Reference for Intel® Data Analytics Acceleration Library 2018 Update 2

svm_model.h
1 /* file: svm_model.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 /*
43 //++
44 // Implementation of the class defining the SVM model.
45 //--
46 */
47 
48 #ifndef __SVM_MODEL_H__
49 #define __SVM_MODEL_H__
50 
51 #include "data_management/data/homogen_numeric_table.h"
52 #include "data_management/data/csr_numeric_table.h"
53 #include "algorithms/model.h"
54 #include "algorithms/kernel_function/kernel_function.h"
55 #include "algorithms/kernel_function/kernel_function_linear.h"
56 #include "algorithms/kernel_function/kernel_function_types.h"
57 #include "algorithms/classifier/classifier_model.h"
58 
59 namespace daal
60 {
61 namespace algorithms
62 {
72 namespace svm
73 {
77 namespace interface1
78 {
89 /* [Parameter source code] */
90 struct DAAL_EXPORT Parameter : public classifier::Parameter
91 {
92  Parameter(const services::SharedPtr<kernel_function::KernelIface> &kernelForParameter
93  = services::SharedPtr<kernel_function::KernelIface>(new kernel_function::linear::Batch<>()),
94  double C = 1.0,
95  double accuracyThreshold = 0.001,
96  double tau = 1.0e-6,
97  size_t maxIterations = 1000000,
98  size_t cacheSize = 8000000,
99  bool doShrinking = true,
100  size_t shrinkingStep = 1000) :
101  C(C), accuracyThreshold(accuracyThreshold), tau(tau), maxIterations(maxIterations), cacheSize(cacheSize),
102  doShrinking(doShrinking), shrinkingStep(shrinkingStep), kernel(kernelForParameter) {};
103 
104  double C;
105  double accuracyThreshold;
106  double tau;
107  size_t maxIterations;
108  size_t cacheSize;
110  bool doShrinking;
111  size_t shrinkingStep;
112  algorithms::kernel_function::KernelIfacePtr kernel;
114  services::Status check() const DAAL_C11_OVERRIDE;
115 };
116 /* [Parameter source code] */
117 
127 class DAAL_EXPORT Model : public classifier::Model
128 {
129 public:
130  DECLARE_MODEL(Model, classifier::Model);
131 
140  template<typename modelFPType>
141  Model(modelFPType dummy, size_t nColumns, data_management::NumericTableIface::StorageLayout layout = data_management::NumericTableIface::aos) :
142  _bias(0.0)
143  {
144  using namespace data_management;
145  if (layout == NumericTableIface::csrArray)
146  {
147  modelFPType *dummyPtr = NULL;
148  _SV.reset(new CSRNumericTable(dummyPtr,NULL,NULL,nColumns));
149  }
150  else
151  {
152  _SV.reset(new HomogenNumericTable<modelFPType>(NULL, nColumns, 0));
153  }
154  _SVCoeff.reset(new HomogenNumericTable<modelFPType>(NULL, 1, 0));
155  _SVIndices.reset(new HomogenNumericTable<int>(NULL, 1, 0));
156  }
157 
166  template<typename modelFPType>
167  DAAL_EXPORT static services::SharedPtr<Model> create(size_t nColumns,
168  data_management::NumericTableIface::StorageLayout layout = data_management::NumericTableIface::aos,
169  services::Status *stat = NULL);
170 
175  Model() : _SV(), _SVIndices(), _SVCoeff(), _bias(0.0) {}
176 
182  static services::SharedPtr<Model> create(services::Status *stat = NULL)
183  {
184  services::SharedPtr<Model> modelPtr(new Model());
185  if (!modelPtr)
186  {
187  if (stat)
188  stat->add(services::ErrorMemoryAllocationFailed);
189  }
190  return modelPtr;
191  }
192 
193  virtual ~Model() {}
194 
199  data_management::NumericTablePtr getSupportVectors() { return _SV; }
200 
205  data_management::NumericTablePtr getSupportIndices() { return _SVIndices; }
206 
211  data_management::NumericTablePtr getClassificationCoefficients() { return _SVCoeff; }
212 
217  virtual double getBias() { return _bias; }
218 
223  virtual void setBias(double bias)
224  {
225  _bias = bias;
226  }
227 
232  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE { return (_SV ? _SV->getNumberOfColumns() : 0); }
233 
234 protected:
235  data_management::NumericTablePtr _SV;
236  data_management::NumericTablePtr _SVCoeff;
237  double _bias;
238  data_management::NumericTablePtr _SVIndices;
240  template<typename modelFPType>
241  DAAL_EXPORT Model(modelFPType dummy, size_t nColumns, data_management::NumericTableIface::StorageLayout layout,
242  services::Status &st);
243 
244  template<typename Archive, bool onDeserialize>
245  services::Status serialImpl(Archive *arch)
246  {
247  services::Status st = classifier::Model::serialImpl<Archive, onDeserialize>(arch);
248  if (!st)
249  return st;
250  arch->setSharedPtrObj(_SV);
251  arch->setSharedPtrObj(_SVCoeff);
252  arch->set(_bias);
253 
254  arch->setSharedPtrObj(_SVIndices);
255 
256  return st;
257  }
258 };
259 typedef services::SharedPtr<Model> ModelPtr;
261 } // namespace interface1
262 using interface1::Parameter;
263 using interface1::Model;
264 using interface1::ModelPtr;
265 
266 } // namespace svm
268 } // namespace algorithms
269 } // namespace daal
270 #endif
daal::algorithms::svm::interface1::Parameter
Optional parameters.
Definition: svm_model.h:90
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
daal
Definition: algorithm_base_common.h:57
daal::algorithms::svm::interface1::Model::getSupportIndices
data_management::NumericTablePtr getSupportIndices()
Definition: svm_model.h:205
daal::algorithms::classifier::interface1::Parameter
Base class for the parameters of the classification algorithm.
Definition: classifier_model.h:81
daal::algorithms::svm::interface1::Model
Model of the classifier trained by the svm::training::Batch algorithm
Definition: svm_model.h:127
daal::algorithms::svm::interface1::Model::create
static services::SharedPtr< Model > create(services::Status *stat=NULL)
Definition: svm_model.h:182
daal::algorithms::svm::interface1::Parameter::accuracyThreshold
double accuracyThreshold
Definition: svm_model.h:105
daal::algorithms::svm::interface1::Parameter::shrinkingStep
size_t shrinkingStep
Definition: svm_model.h:111
daal::services::ErrorMemoryAllocationFailed
Definition: error_indexes.h:172
daal::algorithms::svm::interface1::Parameter::tau
double tau
Definition: svm_model.h:106
daal::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::algorithms::svm::interface1::Model::getBias
virtual double getBias()
Definition: svm_model.h:217
daal::algorithms::classifier::interface1::Model
Base class for the model of the classification algorithm.
Definition: classifier_model.h:95
daal::data_management::interface1::NumericTableIface::StorageLayout
StorageLayout
Storage layouts that may need to be supported.
Definition: numeric_table.h:352
daal::algorithms::svm::interface1::Parameter::doShrinking
bool doShrinking
Definition: svm_model.h:110
daal::algorithms::svm::interface1::Parameter::cacheSize
size_t cacheSize
Definition: svm_model.h:108
daal::algorithms::svm::interface1::Parameter::C
double C
Definition: svm_model.h:102
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:141
daal::algorithms::kernel_function::linear::interface1::Batch
Computes a linear kernel function in the batch processing mode.
Definition: kernel_function_linear.h:117
daal::algorithms::svm::interface1::Model::setBias
virtual void setBias(double bias)
Definition: svm_model.h:223
daal::algorithms::svm::interface1::Model::getClassificationCoefficients
data_management::NumericTablePtr getClassificationCoefficients()
Definition: svm_model.h:211
daal::algorithms::svm::interface1::Model::getSupportVectors
data_management::NumericTablePtr getSupportVectors()
Definition: svm_model.h:199
daal::algorithms::svm::interface1::Model::Model
Model()
Definition: svm_model.h:175
daal::algorithms::svm::interface1::Parameter::maxIterations
size_t maxIterations
Definition: svm_model.h:107
daal::algorithms::svm::interface1::Model::getNumberOfFeatures
size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE
Definition: svm_model.h:232

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