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

svm_model.h
1 /* file: svm_model.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 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  services::SharedPtr<kernel_function::KernelIface> 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  }
156 
165  template<typename modelFPType>
166  DAAL_EXPORT static services::SharedPtr<Model> create(size_t nColumns,
167  data_management::NumericTableIface::StorageLayout layout = data_management::NumericTableIface::aos,
168  services::Status *stat = NULL);
169 
174  Model() : _SV(), _SVCoeff(), _bias(0.0) {}
175 
181  static services::SharedPtr<Model> create(services::Status *stat = NULL)
182  {
183  services::SharedPtr<Model> modelPtr(new Model());
184  if (!modelPtr)
185  {
186  if (stat)
187  stat->add(services::ErrorMemoryAllocationFailed);
188  }
189  return modelPtr;
190  }
191 
192  virtual ~Model() {}
193 
198  data_management::NumericTablePtr getSupportVectors() { return _SV; }
199 
204  data_management::NumericTablePtr getClassificationCoefficients() { return _SVCoeff; }
205 
210  virtual double getBias() { return _bias; }
211 
216  virtual void setBias(double bias)
217  {
218  _bias = bias;
219  }
220 
225  size_t getNumberOfFeatures() const DAAL_C11_OVERRIDE { return (_SV ? _SV->getNumberOfColumns() : 0); }
226 
227 protected:
228  data_management::NumericTablePtr _SV;
229  data_management::NumericTablePtr _SVCoeff;
230  double _bias;
232  template<typename modelFPType>
233  DAAL_EXPORT Model(modelFPType dummy, size_t nColumns, data_management::NumericTableIface::StorageLayout layout,
234  services::Status &st);
235 
236  template<typename Archive, bool onDeserialize>
237  services::Status serialImpl(Archive *arch)
238  {
239  services::Status st = classifier::Model::serialImpl<Archive, onDeserialize>(arch);
240  if (!st)
241  return st;
242  arch->setSharedPtrObj(_SV);
243  arch->setSharedPtrObj(_SVCoeff);
244  arch->set(_bias);
245 
246  return st;
247  }
248 };
249 typedef services::SharedPtr<Model> ModelPtr;
251 } // namespace interface1
252 using interface1::Parameter;
253 using interface1::Model;
254 using interface1::ModelPtr;
255 
256 } // namespace svm
258 } // namespace algorithms
259 } // namespace daal
260 #endif
daal::algorithms::svm::interface1::Parameter
Optional parameters.
Definition: svm_model.h:90
daal
Definition: algorithm_base_common.h:57
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::Parameter::kernel
services::SharedPtr< kernel_function::KernelIface > kernel
Definition: svm_model.h:112
daal::algorithms::svm::interface1::Model::create
static services::SharedPtr< Model > create(services::Status *stat=NULL)
Definition: svm_model.h:181
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:170
daal::algorithms::svm::interface1::Parameter::tau
double tau
Definition: svm_model.h:106
daal::algorithms::svm::interface1::Model::getBias
virtual double getBias()
Definition: svm_model.h:210
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::Model::Model
Model(modelFPType dummy, size_t nColumns, data_management::NumericTableIface::StorageLayout layout=data_management::NumericTableIface::aos)
Definition: svm_model.h:141
daal::algorithms::svm::interface1::Model::setBias
virtual void setBias(double bias)
Definition: svm_model.h:216
daal::algorithms::svm::interface1::Model::getClassificationCoefficients
data_management::NumericTablePtr getClassificationCoefficients()
Definition: svm_model.h:204
daal::algorithms::svm::interface1::Model::getSupportVectors
data_management::NumericTablePtr getSupportVectors()
Definition: svm_model.h:198
daal::algorithms::svm::interface1::Model::Model
Model()
Definition: svm_model.h:174
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:225

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