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

neural_networks_prediction.h
1 /* file: neural_networks_prediction.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 neural network model-based prediction
19 // in the batch processing mode
20 //--
21 */
22 
23 #ifndef __NEURAL_NETWORKS_PREDICTION_H__
24 #define __NEURAL_NETWORKS_PREDICTION_H__
25 
26 #include "algorithms/algorithm.h"
27 
28 #include "services/daal_defines.h"
29 #include "algorithms/neural_networks/neural_networks_types.h"
30 #include "algorithms/neural_networks/neural_networks_prediction_types.h"
31 #include "algorithms/neural_networks/neural_networks_prediction_model.h"
32 #include "algorithms/neural_networks/layers/layer.h"
33 
34 namespace daal
35 {
36 namespace algorithms
37 {
41 namespace neural_networks
42 {
43 namespace prediction
44 {
45 namespace interface1
46 {
56 template<typename algorithmFPType, Method method, CpuType cpu>
57 class DAAL_EXPORT BatchContainer : public PredictionContainerIface
58 {
59 public:
65  BatchContainer(daal::services::Environment::env *daalEnv);
67  ~BatchContainer();
71  services::Status compute() DAAL_C11_OVERRIDE;
72  services::Status setupCompute() DAAL_C11_OVERRIDE;
73  services::Status resetCompute() DAAL_C11_OVERRIDE;
74 };
75 
91 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
92 class Batch : public daal::algorithms::Prediction
93 {
94 public:
95  typedef algorithms::neural_networks::prediction::Input InputType;
96  typedef algorithms::neural_networks::prediction::Parameter ParameterType;
97  typedef algorithms::neural_networks::prediction::Result ResultType;
98 
100  Batch()
101  {
102  initialize();
103  };
104 
110  Batch(const Batch<algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
111  {
112  initialize();
113  }
114 
115  virtual ~Batch() {}
116 
121  ResultPtr getResult()
122  {
123  return _result;
124  }
125 
132  services::Status setResult(const ResultPtr& res)
133  {
134  DAAL_CHECK(res, services::ErrorNullResult)
135  _result = res;
136  _res = _result.get();
137  return services::Status();
138  }
139 
145  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
146  {
147  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
148  }
149 
154  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
155 
156  InputType input;
157  ParameterType parameter;
159 protected:
160  void initialize()
161  {
162  Prediction::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
163  _in = &input;
164  _par = &parameter;
165  _result.reset(new ResultType());
166  }
167 
168  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
169  {
170  return new Batch<algorithmFPType, method>(*this);
171  }
172 
173  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
174  {
175  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
176  _res = _result.get();
177  return s;
178  }
179 
180 private:
181  ResultPtr _result;
182 };
183 
185 } // namespace interface1
186 using interface1::Batch;
187 using interface1::BatchContainer;
188 
189 } // namespace prediction
190 } // namespace neural_networks
191 } // namespace algorithms
192 } // namespace daal
193 #endif
daal::algorithms::neural_networks::prediction::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: neural_networks_prediction.h:110
daal
Definition: algorithm_base_common.h:31
daal::algorithms::Prediction
Provides prediction methods depending on the model such as linear_regression::Model. The methods of the class support different computation modes: batch, distributed, and online(see ComputeMode). Classes that implement specific algorithms of the model based data prediction are derived classes of the Prediction class. The class additionally provides virtual methods for validation of input and output parameters of the algorithms.
Definition: prediction.h:50
daal::algorithms::neural_networks::prediction::interface1::BatchContainer
Class containing methods to train neural network model using algorithmFPType precision arithmetic...
Definition: neural_networks_prediction.h:57
daal::algorithms::neural_networks::prediction::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: neural_networks_prediction.h:145
daal::algorithms::PredictionContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the algor...
Definition: prediction.h:40
daal::algorithms::neural_networks::prediction::interface1::Batch::getResult
ResultPtr getResult()
Definition: neural_networks_prediction.h:121
daal_defines.h
daal::batch
Definition: daal_defines.h:106
daal::algorithms::neural_networks::prediction::interface1::Batch::Batch
Batch()
Definition: neural_networks_prediction.h:100
daal::algorithms::neural_networks::prediction::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_prediction.h:154
daal::algorithms::neural_networks::prediction::interface1::Batch
Provides methods for neural network model-based prediction in the batch processing mode...
Definition: neural_networks_prediction.h:92
daal::algorithms::classifier::prediction::prediction
Definition: classifier_predict_types.h:76
daal::algorithms::neural_networks::prediction::interface1::Batch::setResult
services::Status setResult(const ResultPtr &res)
Definition: neural_networks_prediction.h:132
daal::algorithms::neural_networks::prediction::interface1::Batch::parameter
ParameterType parameter
Definition: neural_networks_prediction.h:157
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::neural_networks::prediction::interface1::Batch::input
InputType input
Definition: neural_networks_prediction.h:156

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