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

neural_networks_training.h
1 /* file: neural_networks_training.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 training
19 // in the batch processing mode
20 //--
21 */
22 
23 #ifndef __NEURAL_NETWORKS_TRAINING_H__
24 #define __NEURAL_NETWORKS_TRAINING_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_training_types.h"
31 #include "algorithms/neural_networks/neural_networks_training_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 training
44 {
45 namespace interface1
46 {
56 template<typename algorithmFPType, Method method, CpuType cpu>
57 class DAAL_EXPORT BatchContainer : public TrainingContainerIface<batch>
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::Training<batch>
93 {
94 public:
95  typedef algorithms::neural_networks::training::Input InputType;
96  typedef algorithms::neural_networks::training::Parameter ParameterType;
97  typedef algorithms::neural_networks::training::Result ResultType;
98 
100  Batch(services::SharedPtr<optimization_solver::iterative_solver::Batch > optimizationSolver_) : parameter(optimizationSolver_)
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 
124  services::Status initialize(const services::Collection<size_t> &sampleSize, const training::Topology &topology)
125  {
126  ResultPtr result = getResult();
127  if (!result || !result->get(neural_networks::training::model))
128  {
129  return services::Status(services::ErrorNullModel);
130  }
131  _result->get(neural_networks::training::model)->initialize<algorithmFPType>(sampleSize, topology, parameter);
132  return services::Status();
133  }
134 
139  ResultPtr getResult()
140  {
141  return _result;
142  }
143 
150  services::Status setResult(const ResultPtr& res)
151  {
152  DAAL_CHECK(res, services::ErrorNullResult)
153  _result = res;
154  _res = _result.get();
155  return services::Status();
156  }
157 
163  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
164  {
165  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
166  }
167 
172  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
173 
174  InputType input;
175  ParameterType parameter;
177 protected:
178  void initialize()
179  {
180  Training<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
181  _in = &input;
182  _par = &parameter;
183  _result.reset(new ResultType());
184  }
185 
186  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
187  {
188  return new Batch<algorithmFPType, method>(*this);
189  }
190 
191  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
192  {
193  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
194  _res = _result.get();
195  return s;
196  }
197 
198 private:
199  ResultPtr _result;
200 };
202 } // namespace interface1
203 using interface1::Batch;
204 using interface1::BatchContainer;
205 
206 } // namespace training
207 } // namespace neural_networks
208 } // namespace algorithms
209 } // namespace daal
210 #endif
daal::algorithms::neural_networks::training::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: neural_networks_training.h:163
daal::algorithms::neural_networks::training::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: neural_networks_training.h:110
daal
Definition: algorithm_base_common.h:31
daal::algorithms::neural_networks::training::interface1::Batch::parameter
ParameterType parameter
Definition: neural_networks_training.h:175
daal::algorithms::neural_networks::training::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training.h:172
daal::algorithms::neural_networks::training::interface1::Batch::Batch
Batch(services::SharedPtr< optimization_solver::iterative_solver::Batch > optimizationSolver_)
Definition: neural_networks_training.h:100
daal::algorithms::neural_networks::training::interface1::BatchContainer
Class containing methods to train neural network model using algorithmFPType precision arithmetic...
Definition: neural_networks_training.h:57
daal::algorithms::neural_networks::training::interface1::Batch
Provides methods for neural network model-based training in the batch processing mode.
Definition: neural_networks_training.h:92
daal_defines.h
daal::batch
Definition: daal_defines.h:106
daal::algorithms::neural_networks::training::interface1::Batch::getResult
ResultPtr getResult()
Definition: neural_networks_training.h:139
daal::algorithms::neural_networks::training::interface1::Batch::input
InputType input
Definition: neural_networks_training.h:174
daal::services::ErrorNullModel
Definition: error_indexes.h:83
daal::algorithms::neural_networks::training::interface1::Batch::initialize
services::Status initialize(const services::Collection< size_t > &sampleSize, const training::Topology &topology)
Definition: neural_networks_training.h:124
daal::algorithms::neural_networks::training::model
Definition: neural_networks_training_result.h:52
daal::algorithms::neural_networks::training::interface1::Batch::setResult
services::Status setResult(const ResultPtr &res)
Definition: neural_networks_training.h:150
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:50
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:60

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