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

neural_networks_training.h
1 /* file: neural_networks_training.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 neural network model-based training
21 // in the batch processing mode
22 //--
23 */
24 
25 #ifndef __NEURAL_NETWORKS_TRAINING_H__
26 #define __NEURAL_NETWORKS_TRAINING_H__
27 
28 #include "algorithms/algorithm.h"
29 
30 #include "services/daal_defines.h"
31 #include "algorithms/neural_networks/neural_networks_types.h"
32 #include "algorithms/neural_networks/neural_networks_training_types.h"
33 #include "algorithms/neural_networks/neural_networks_training_model.h"
34 #include "algorithms/neural_networks/layers/layer.h"
35 
36 namespace daal
37 {
38 namespace algorithms
39 {
43 namespace neural_networks
44 {
45 namespace training
46 {
47 namespace interface1
48 {
59 template<typename algorithmFPType, Method method, CpuType cpu>
60 class BatchContainer : public TrainingContainerIface<batch>
61 {
62 public:
69  DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv);
74  DAAL_DEPRECATED ~BatchContainer();
79  DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE;
83  DAAL_DEPRECATED services::Status setupCompute() DAAL_C11_OVERRIDE;
87  DAAL_DEPRECATED services::Status resetCompute() DAAL_C11_OVERRIDE;
88 };
89 
107 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
108 class Batch : public daal::algorithms::Training<batch>
109 {
110 public:
111  typedef algorithms::neural_networks::training::Input InputType;
112  typedef algorithms::neural_networks::training::Parameter ParameterType;
113  typedef algorithms::neural_networks::training::Result ResultType;
114 
119  DAAL_DEPRECATED Batch(services::SharedPtr<optimization_solver::iterative_solver::Batch > optimizationSolver_) : parameter(optimizationSolver_)
120  {
121  initialize();
122  };
123 
130  Batch(const Batch<algorithmFPType, method> &other) : parameter(other.parameter), input(other.input)
131  {
132  initialize();
133  }
134 
138  virtual ~Batch() {}
139 
148  DAAL_DEPRECATED services::Status initialize(const services::Collection<size_t> &sampleSize, const training::Topology &topology)
149  {
150  ResultPtr result = getResult();
151  if (!result || !result->get(neural_networks::training::model))
152  {
153  return services::Status(services::ErrorNullModel);
154  }
155  _result->get(neural_networks::training::model)->initialize<algorithmFPType>(sampleSize, topology, parameter);
156  return services::Status();
157  }
158 
164  ResultPtr getResult()
165  {
166  return _result;
167  }
168 
176  DAAL_DEPRECATED services::Status setResult(const ResultPtr& res)
177  {
178  DAAL_CHECK(res, services::ErrorNullResult)
179  _result = res;
180  _res = _result.get();
181  return services::Status();
182  }
183 
190  DAAL_DEPRECATED services::SharedPtr<Batch<algorithmFPType, method> > clone() const
191  {
192  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
193  }
194 
200  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
201 
202  InputType input;
203  ParameterType parameter;
205 protected:
209  void initialize()
210  {
211  Training<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
212  _in = &input;
213  _par = &parameter;
214  _result.reset(new ResultType());
215  }
216 
220  DAAL_DEPRECATED_VIRTUAL virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
221  {
222  return new Batch<algorithmFPType, method>(*this);
223  }
224 
228  DAAL_DEPRECATED_VIRTUAL virtual services::Status allocateResult() DAAL_C11_OVERRIDE
229  {
230  services::Status s = _result->allocate<algorithmFPType>(&input, &parameter, (int) method);
231  _res = _result.get();
232  return s;
233  }
234 
235 private:
236  ResultPtr _result;
237 };
239 } // namespace interface1
240 using interface1::Batch;
241 using interface1::BatchContainer;
242 
243 } // namespace training
244 } // namespace neural_networks
245 } // namespace algorithms
246 } // namespace daal
247 #endif
daal::batch
Definition: daal_defines.h:112
daal::algorithms::neural_networks::training::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: neural_networks_training.h:130
daal::algorithms::neural_networks::training::interface1::BatchContainer::compute
DAAL_DEPRECATED services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::neural_networks::training::interface1::Batch::~Batch
virtual ~Batch()
Definition: neural_networks_training.h:138
daal::algorithms::neural_networks::training::interface1::Batch::Batch
DAAL_DEPRECATED Batch(services::SharedPtr< optimization_solver::iterative_solver::Batch > optimizationSolver_)
Definition: neural_networks_training.h:119
daal::algorithms::neural_networks::training::interface1::Batch::getResult
ResultPtr getResult()
Definition: neural_networks_training.h:164
daal::algorithms::neural_networks::training::interface1::BatchContainer::setupCompute
DAAL_DEPRECATED services::Status setupCompute() DAAL_C11_OVERRIDE
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:108
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::neural_networks::training::interface1::Batch::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: neural_networks_training.h:200
daal::algorithms::neural_networks::training::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::neural_networks::training::interface1::Batch::setResult
DAAL_DEPRECATED services::Status setResult(const ResultPtr &res)
Definition: neural_networks_training.h:176
daal_defines.h
daal::algorithms::neural_networks::training::interface1::Batch::allocateResult
virtual DAAL_DEPRECATED_VIRTUAL services::Status allocateResult() DAAL_C11_OVERRIDE
Definition: neural_networks_training.h:228
daal::services::ErrorNullModel
Definition: error_indexes.h:85
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:62
daal::algorithms::neural_networks::training::interface1::Batch::parameter
ParameterType parameter
Definition: neural_networks_training.h:203
daal::algorithms::neural_networks::training::interface1::Batch::initialize
void initialize()
Definition: neural_networks_training.h:209
daal::algorithms::neural_networks::training::interface1::Batch::cloneImpl
virtual DAAL_DEPRECATED_VIRTUAL Batch< algorithmFPType, method > * cloneImpl() const DAAL_C11_OVERRIDE
Definition: neural_networks_training.h:220
daal::algorithms::neural_networks::training::interface1::Batch::clone
DAAL_DEPRECATED services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: neural_networks_training.h:190
daal::algorithms::neural_networks::training::interface1::Batch::initialize
DAAL_DEPRECATED services::Status initialize(const services::Collection< size_t > &sampleSize, const training::Topology &topology)
Definition: neural_networks_training.h:148
daal::algorithms::neural_networks::training::interface1::BatchContainer::resetCompute
DAAL_DEPRECATED services::Status resetCompute() DAAL_C11_OVERRIDE
daal::algorithms::neural_networks::training::model
Definition: neural_networks_training_result.h:54
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52
daal::algorithms::neural_networks::training::interface1::BatchContainer::~BatchContainer
DAAL_DEPRECATED ~BatchContainer()
daal::algorithms::neural_networks::training::interface1::Batch::input
InputType input
Definition: neural_networks_training.h:202
daal::algorithms::neural_networks::training::interface1::BatchContainer
Class containing methods to train neural network model using algorithmFPType precision arithmetic...
Definition: neural_networks_training.h:60

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