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

sgd_batch.h
1 /* file: sgd_batch.h */
2 /*******************************************************************************
3 * Copyright 2014-2019 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 the stochastic gradient descent (SGD) algorithm
19 // in the batch processing mode
20 //--
21 */
22 
23 #ifndef __SGD_BATCH_H__
24 #define __SGD_BATCH_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "algorithms/optimization_solver/iterative_solver/iterative_solver_batch.h"
30 #include "sgd_types.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
36 namespace optimization_solver
37 {
38 namespace sgd
39 {
40 namespace interface1
41 {
55 template<typename algorithmFPType, Method method, CpuType cpu>
56 class DAAL_EXPORT BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
57 {
58 public:
64  BatchContainer(daal::services::Environment::env *daalEnv);
66  ~BatchContainer();
72  virtual services::Status compute() DAAL_C11_OVERRIDE;
73 };
74 
92 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
93 class DAAL_EXPORT Batch : public iterative_solver::interface1::Batch
94 {
95 public:
96  typedef algorithms::optimization_solver::sgd::interface1::Input InputType;
97  typedef algorithms::optimization_solver::sgd::interface1::Parameter<method> ParameterType;
98  typedef algorithms::optimization_solver::sgd::interface1::Result ResultType;
99 
100  InputType input;
101  Parameter<method> parameter;
107  Batch(const sum_of_functions::interface1::BatchPtr& objectiveFunction = sum_of_functions::interface1::BatchPtr()) :
108  input(),
109  parameter(objectiveFunction)
110  {
111  initialize();
112  }
113 
120  Batch(const Batch<algorithmFPType, method> &other) :
121  iterative_solver::interface1::Batch(other),
122  input(other.input),
123  parameter(other.parameter)
124  {
125  initialize();
126  }
127 
132  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
133 
138  virtual iterative_solver::interface1::Input * getInput() DAAL_C11_OVERRIDE { return &input; }
139 
144  virtual iterative_solver::interface1::Parameter * getParameter() DAAL_C11_OVERRIDE { return &parameter; }
145 
151  virtual services::Status createResult() DAAL_C11_OVERRIDE
152  {
153  _result = iterative_solver::interface1::ResultPtr(new ResultType());
154  _res = NULL;
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  static services::SharedPtr<Batch<algorithmFPType, method> > create();
173 
174 protected:
175  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
176  {
177  return new Batch<algorithmFPType, method>(*this);
178  }
179 
180  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
181  {
182  services::Status s = static_cast<ResultType*>(_result.get())->allocate<algorithmFPType>(&input, &parameter, (int)method);
183  _res = _result.get();
184  return s;
185  }
186 
187  void initialize()
188  {
189  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
190  _par = &parameter;
191  _in = &input;
192  _result = iterative_solver::interface1::ResultPtr(new ResultType());
193  }
194 };
196 } // namespace interface1
197 
198 namespace interface2
199 {
213 template<typename algorithmFPType, Method method, CpuType cpu>
214 class DAAL_EXPORT BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
215 {
216 public:
222  BatchContainer(daal::services::Environment::env *daalEnv);
224  ~BatchContainer();
230  virtual services::Status compute() DAAL_C11_OVERRIDE;
231 };
232 
250 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
251 class DAAL_EXPORT Batch : public iterative_solver::Batch
252 {
253 public:
254  typedef algorithms::optimization_solver::sgd::Input InputType;
255  typedef algorithms::optimization_solver::sgd::Parameter<method> ParameterType;
256  typedef algorithms::optimization_solver::sgd::Result ResultType;
257 
258  InputType input;
259  Parameter<method> parameter;
265  Batch(const sum_of_functions::BatchPtr& objectiveFunction = sum_of_functions::BatchPtr()) :
266  input(),
267  parameter(objectiveFunction)
268  {
269  initialize();
270  }
271 
278  Batch(const Batch<algorithmFPType, method> &other) :
279  iterative_solver::Batch(other),
280  input(other.input),
281  parameter(other.parameter)
282  {
283  initialize();
284  }
285 
290  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
291 
296  virtual iterative_solver::Input * getInput() DAAL_C11_OVERRIDE { return &input; }
297 
302  virtual iterative_solver::Parameter * getParameter() DAAL_C11_OVERRIDE { return &parameter; }
303 
309  virtual services::Status createResult() DAAL_C11_OVERRIDE
310  {
311  _result = iterative_solver::ResultPtr(new ResultType());
312  _res = NULL;
313  return services::Status();
314  }
315 
321  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
322  {
323  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
324  }
325 
330  static services::SharedPtr<Batch<algorithmFPType, method> > create();
331 
332 protected:
333  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
334  {
335  return new Batch<algorithmFPType, method>(*this);
336  }
337 
338  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
339  {
340  services::Status s = static_cast<ResultType*>(_result.get())->allocate<algorithmFPType>(&input, &parameter, (int)method);
341  _res = _result.get();
342  return s;
343  }
344 
345  void initialize()
346  {
347  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
348  _par = &parameter;
349  _in = &input;
350  _result = iterative_solver::ResultPtr(new ResultType());
351  }
352 };
354 } // namespace interface2
355 
356 using interface2::BatchContainer;
357 using interface2::Batch;
358 
359 } // namespace sgd
360 } // namespace optimization_solver
361 } // namespace algorithm
362 } // namespace daal
363 #endif
daal::algorithms::optimization_solver::sgd::interface1::Batch::input
InputType input
Definition: sgd_batch.h:100
daal
Definition: algorithm_base_common.h:31
daal::algorithms::optimization_solver::iterative_solver::interface1::Result
Results obtained with the compute() method of the iterative solver algorithm in the batch processing ...
Definition: iterative_solver_types.h:221
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:53
daal::algorithms::optimization_solver::sgd::interface2::Batch::createResult
virtual services::Status createResult() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:309
daal::algorithms::optimization_solver::sgd::interface1::Parameter
Definition: sgd_types.h:130
daal::algorithms::optimization_solver::sgd::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: sgd_batch.h:132
daal::algorithms::optimization_solver::sgd::interface2::Batch::parameter
Parameter< method > parameter
Definition: sgd_batch.h:259
daal::algorithms::optimization_solver::sgd::interface1::Input
Input for the Stochastic gradient descent algorithm
Definition: sgd_types.h:284
daal::algorithms::optimization_solver::iterative_solver::interface1::Parameter
Parameter base class for the iterative solver algorithm
Definition: iterative_solver_types.h:113
daal::algorithms::optimization_solver::iterative_solver::interface1::Input
Input parameters for the iterative solver algorithm
Definition: iterative_solver_types.h:158
daal::algorithms::optimization_solver::sgd::interface2::BatchContainer
Provides methods to run implementations of the stochastic gradient descent algorithm. This class is associated with daal::algorithms::optimization_solver::sgd::BatchContainer class.
Definition: sgd_batch.h:214
daal_defines.h
daal::algorithms::optimization_solver::sgd::interface1::Batch::Batch
Batch(const sum_of_functions::interface1::BatchPtr &objectiveFunction=sum_of_functions::interface1::BatchPtr())
Definition: sgd_batch.h:107
daal::batch
Definition: daal_defines.h:110
daal::algorithms::optimization_solver::sgd::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: sgd_batch.h:120
daal::algorithms::optimization_solver::sgd::interface1::BatchContainer
Provides methods to run implementations of the stochastic gradient descent algorithm. This class is associated with daal::algorithms::optimization_solver::sgd::BatchContainer class.
Definition: sgd_batch.h:56
daal::algorithms::optimization_solver::sgd::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: sgd_batch.h:290
daal::algorithms::optimization_solver::sgd::interface1::Batch::parameter
Parameter< method > parameter
Definition: sgd_batch.h:101
daal::algorithms::optimization_solver::sgd::interface1::Result
Results obtained with the compute() method of the sgd algorithm in the batch processing mode...
Definition: sgd_types.h:324
daal::algorithms::optimization_solver::sgd::interface1::Batch
Computes Stochastic gradient descent in the batch processing mode.
Definition: sgd_batch.h:93
daal::algorithms::optimization_solver::sgd::interface2::Parameter
Definition: sgd_types.h:436
daal::algorithms::optimization_solver::sgd::interface2::Batch
Computes Stochastic gradient descent in the batch processing mode.
Definition: sgd_batch.h:251
daal::algorithms::optimization_solver::sgd::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: sgd_batch.h:163
daal::algorithms::optimization_solver::sgd::interface2::Batch::input
InputType input
Definition: sgd_batch.h:258
daal::algorithms::optimization_solver::sgd::interface2::Batch::Batch
Batch(const sum_of_functions::BatchPtr &objectiveFunction=sum_of_functions::BatchPtr())
Definition: sgd_batch.h:265
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:68
daal::algorithms::optimization_solver::sgd::interface1::Batch::createResult
virtual services::Status createResult() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:151
daal::algorithms::optimization_solver::sgd::interface1::Batch::getParameter
virtual iterative_solver::interface1::Parameter * getParameter() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:144
daal::algorithms::optimization_solver::sgd::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: sgd_batch.h:278
daal::algorithms::optimization_solver::iterative_solver::interface1::Batch
Interface for computing the iterative solver in the batch processing mode.
Definition: iterative_solver_batch.h:52
daal::algorithms::optimization_solver::sgd::interface1::Batch::getInput
virtual iterative_solver::interface1::Input * getInput() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:138
daal::algorithms::kmeans::objectiveFunction
Definition: kmeans_types.h:109
daal::algorithms::optimization_solver::sgd::interface2::Batch::getInput
virtual iterative_solver::Input * getInput() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:296
daal::algorithms::optimization_solver::sgd::interface2::Batch::getParameter
virtual iterative_solver::Parameter * getParameter() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:302
daal::algorithms::optimization_solver::sgd::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: sgd_batch.h:321

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