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

svm_predict.h
1 /* file: svm_predict.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 prediction
21 //--
22 */
23 
24 #ifndef __SVM_PREDICT_H__
25 #define __SVM_PREDICT_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "data_management/data/numeric_table.h"
29 #include "algorithms/classifier/classifier_predict.h"
30 #include "algorithms/svm/svm_predict_types.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
36 namespace svm
37 {
38 namespace prediction
39 {
43 namespace interface1
44 {
59 template<typename algorithmFPType, Method method, CpuType cpu>
60 class BatchContainer : public PredictionContainerIface
61 {
62 public:
67  BatchContainer(daal::services::Environment::env *daalEnv);
69  ~BatchContainer();
75  services::Status compute() DAAL_C11_OVERRIDE;
76 };
77 
95 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
96 class Batch : public classifier::prediction::interface1::Batch
97 {
98 public:
99  typedef classifier::prediction::interface1::Batch super;
100 
101  typedef algorithms::svm::prediction::Input InputType;
102  typedef algorithms::svm::interface1::Parameter ParameterType;
103  typedef typename super::ResultType ResultType;
104 
105  InputType input;
106  ParameterType parameter;
109  Batch()
110  {
111  initialize();
112  }
113 
120  Batch(const Batch<algorithmFPType, method> &other) : classifier::prediction::interface1::Batch(other),
121  input(other.input), parameter(other.parameter)
122  {
123  initialize();
124  }
125 
126  virtual ~Batch() {}
127 
132  InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
133 
138  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
139 
140 
146  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
147  {
148  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
149  }
150 
151 protected:
152 
153  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
154  {
155  return new Batch<algorithmFPType, method>(*this);
156  }
157 
158  services::Status allocateResult() DAAL_C11_OVERRIDE
159  {
160  services::Status s = _result->allocate<algorithmFPType>(&input, 0, 0);
161  _res = _result.get();
162  return s;
163  }
164 
165  void initialize()
166  {
167  _in = &input;
168  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
169  _par = &parameter;
170  }
171 };
173 } // namespace interface1
174 
178 namespace interface2
179 {
194 template<typename algorithmFPType, Method method, CpuType cpu>
195 class BatchContainer : public PredictionContainerIface
196 {
197 public:
202  BatchContainer(daal::services::Environment::env *daalEnv);
204  ~BatchContainer();
210  services::Status compute() DAAL_C11_OVERRIDE;
211 };
212 
230 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
231 class Batch : public classifier::prediction::Batch
232 {
233 public:
234  typedef classifier::prediction::Batch super;
235 
236  typedef algorithms::svm::prediction::Input InputType;
237  typedef algorithms::svm::Parameter ParameterType;
238  typedef typename super::ResultType ResultType;
239 
240  InputType input;
241  ParameterType parameter;
244  Batch()
245  {
246  initialize();
247  }
248 
255  Batch(const Batch<algorithmFPType, method> &other) : classifier::prediction::Batch(other),
256  input(other.input), parameter(other.parameter)
257  {
258  initialize();
259  }
260 
261  virtual ~Batch() {}
262 
267  InputType * getInput() DAAL_C11_OVERRIDE { return &input; }
268 
273  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
274 
275 
281  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
282  {
283  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
284  }
285 
286 protected:
287 
288  virtual Batch<algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
289  {
290  return new Batch<algorithmFPType, method>(*this);
291  }
292 
293  services::Status allocateResult() DAAL_C11_OVERRIDE
294  {
295  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, 0);
296  _res = _result.get();
297  return s;
298  }
299 
300  void initialize()
301  {
302  _in = &input;
303  _ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
304  _par = &parameter;
305  }
306 };
308 } // namespace interface2
309 using interface2::BatchContainer;
310 using interface2::Batch;
311 
312 } // namespace prediction
313 } // namespace svm
314 } // namespace algorithms
315 } // namespace daal
316 #endif
daal::algorithms::svm::prediction::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: svm_predict.h:255
daal::algorithms::svm::prediction::interface1::BatchContainer
Provides methods to run implementations of the SVM algorithm. It is associated with the Prediction cl...
Definition: svm_predict.h:60
daal::algorithms::svm::prediction::interface1::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::svm::prediction::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: svm_predict.h:281
daal::batch
Definition: daal_defines.h:112
daal::algorithms::svm::prediction::interface2::Batch::getInput
InputType * getInput() DAAL_C11_OVERRIDE
Definition: svm_predict.h:267
daal::algorithms::svm::prediction::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: svm_predict.h:146
daal::algorithms::neural_networks::prediction::prediction
Definition: neural_networks_prediction_result.h:55
daal::algorithms::svm::prediction::interface2::Batch::Batch
Batch()
Definition: svm_predict.h:244
daal::algorithms::svm::prediction::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: svm_predict.h:120
daal::algorithms::svm::prediction::interface1::Batch::parameter
ParameterType parameter
Definition: svm_predict.h:106
daal::algorithms::svm::prediction::interface2::BatchContainer::~BatchContainer
~BatchContainer()
daal::algorithms::classifier::prediction::interface1::Input
Input objects in the prediction stage of the classification algorithm.
Definition: classifier_predict_types.h:111
daal::algorithms::svm::prediction::interface1::BatchContainer::~BatchContainer
~BatchContainer()
daal::algorithms::PredictionContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the algor...
Definition: prediction.h:42
daal::algorithms::classifier::prediction::interface1::Result
Provides methods to access prediction results obtained with the compute() method of the classifier pr...
Definition: classifier_predict_types.h:168
daal::algorithms::svm::prediction::interface2::Batch::parameter
ParameterType parameter
Definition: svm_predict.h:241
daal::algorithms::svm::prediction::interface2::BatchContainer
Provides methods to run implementations of the SVM algorithm. It is associated with the Prediction cl...
Definition: svm_predict.h:195
daal::algorithms::svm::prediction::interface1::BatchContainer::compute
services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::svm::prediction::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svm_predict.h:273
daal::algorithms::classifier::interface1::Parameter
Base class for the parameters of the classification algorithm.
Definition: classifier_model.h:69
daal::algorithms::svm::prediction::interface2::Batch::input
InputType input
Definition: svm_predict.h:240
daal::algorithms::svm::prediction::interface2::BatchContainer::compute
services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::svm::prediction::interface1::Batch
Algorithm class for making predictions based on the SVM model
Definition: svm_predict.h:96
daal::algorithms::svm::interface1::Parameter
Optional parameters.
Definition: svm_model.h:66
daal::algorithms::svm::prediction::interface2::Batch
Algorithm class for making predictions based on the SVM model
Definition: svm_predict.h:231
daal::algorithms::svm::prediction::interface1::Batch::Batch
Batch()
Definition: svm_predict.h:109
daal::algorithms::svm::prediction::interface1::Batch::getInput
InputType * getInput() DAAL_C11_OVERRIDE
Definition: svm_predict.h:132
daal::algorithms::svm::prediction::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: svm_predict.h:138
daal::algorithms::classifier::prediction::interface1::Batch
Base class for making predictions based on the model of the classification algorithms.
Definition: classifier_predict.h:61
daal::algorithms::svm::prediction::interface1::Batch::input
InputType input
Definition: svm_predict.h:105
daal::algorithms::svm::prediction::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)

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