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

sgd_types.h
1 /* file: sgd_types.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 Stochastic gradient descent algorithm types.
19 //--
20 */
21 
22 #ifndef __SGD_TYPES_H__
23 #define __SGD_TYPES_H__
24 
25 #include "algorithms/algorithm.h"
26 #include "data_management/data/numeric_table.h"
27 #include "data_management/data/homogen_numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "algorithms/optimization_solver/iterative_solver/iterative_solver_types.h"
30 #include "algorithms/engines/mt19937/mt19937.h"
31 
32 namespace daal
33 {
34 namespace algorithms
35 {
36 namespace optimization_solver
37 {
47 namespace sgd
48 {
49 
54 enum Method
55 {
56  defaultDense = 0,
57  miniBatch = 1,
58  momentum = 2
59 };
60 
65 enum OptionalDataId
66 {
67  pastUpdateVector = iterative_solver::lastOptionalData + 1,
68  pastWorkValue = pastUpdateVector + 1 ,
69  lastOptionalData = pastWorkValue
70 };
71 
75 namespace interface1
76 {
77 
84 /* [BaseParameter source code] */
85 struct DAAL_EXPORT BaseParameter : public optimization_solver::iterative_solver::Parameter
86 {
98  BaseParameter(
99  const sum_of_functions::BatchPtr &function,
100  size_t nIterations = 100,
101  double accuracyThreshold = 1.0e-05,
102  data_management::NumericTablePtr batchIndices = data_management::NumericTablePtr(),
103  data_management::NumericTablePtr learningRateSequence = data_management::NumericTablePtr(
104  new data_management::HomogenNumericTable<double>(
105  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
106  size_t batchSize = 1,
107  size_t seed = 777 );
108 
109  virtual ~BaseParameter() {}
110 
116  virtual services::Status check() const;
117 
118  data_management::NumericTablePtr batchIndices;
121  data_management::NumericTablePtr learningRateSequence;
122  size_t seed;
124  engines::EnginePtr engine;
126 };
127 /* [BaseParameter source code] */
128 
129 template<Method method>
130 struct Parameter : public BaseParameter {};
131 
138 /* [ParameterDefaultDense source code] */
139 template<>
140 struct DAAL_EXPORT Parameter<defaultDense> : public BaseParameter
141 {
151  Parameter(
152  const sum_of_functions::BatchPtr &function,
153  size_t nIterations = 100,
154  double accuracyThreshold = 1.0e-05,
155  data_management::NumericTablePtr batchIndices = data_management::NumericTablePtr(),
156  data_management::NumericTablePtr learningRateSequence = data_management::NumericTablePtr(
157  new data_management::HomogenNumericTable<double>(
158  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
159  size_t seed = 777 );
160 
166  virtual services::Status check() const;
167 
168  virtual ~Parameter() {}
169 };
170 /* [ParameterDefaultDense source code] */
171 
178 /* [ParameterMiniBatch source code] */
179 template<>
180 struct DAAL_EXPORT Parameter<miniBatch> : public BaseParameter
181 {
197  Parameter(
198  const sum_of_functions::BatchPtr &function,
199  size_t nIterations = 100,
200  double accuracyThreshold = 1.0e-05,
201  data_management::NumericTablePtr batchIndices = data_management::NumericTablePtr(),
202  size_t batchSize = 128,
203  data_management::NumericTablePtr conservativeSequence = data_management::NumericTablePtr(
204  new data_management::HomogenNumericTable<double>(
205  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
206  size_t innerNIterations = 5,
207  data_management::NumericTablePtr learningRateSequence = data_management::NumericTablePtr(
208  new data_management::HomogenNumericTable<double>(
209  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
210  size_t seed = 777 );
211 
217  virtual services::Status check() const;
218 
219  virtual ~Parameter() {}
220 
221  data_management::NumericTablePtr conservativeSequence;
222  size_t innerNIterations;
223 };
224 /* [ParameterMiniBatch source code] */
233 /* [ParameterMomentum source code] */
234 template<>
235 struct DAAL_EXPORT Parameter<momentum> : public BaseParameter
236 {
251  Parameter(
252  const sum_of_functions::BatchPtr& function,
253  double momentum = 0.9,
254  size_t nIterations = 100,
255  double accuracyThreshold = 1.0e-05,
256  data_management::NumericTablePtr batchIndices = data_management::NumericTablePtr(),
257  size_t batchSize = 128,
258  data_management::NumericTablePtr learningRateSequence = data_management::NumericTablePtr(
259  new data_management::HomogenNumericTable<double>(
260  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
261  size_t seed = 777 );
262 
268  virtual services::Status check() const;
269 
270  virtual ~Parameter() {}
271 
272  double momentum;
273 };
274 /* [ParameterMomentum source code] */
283 /* [Input source code] */
284 class DAAL_EXPORT Input : public optimization_solver::iterative_solver::Input
285 {
286 public:
287  typedef optimization_solver::iterative_solver::Input super;
288  Input();
289  Input(const Input& other);
290  using super::set;
291  using super::get;
292 
298  data_management::NumericTablePtr get(OptionalDataId id) const;
299 
305  void set(OptionalDataId id, const data_management::NumericTablePtr &ptr);
306 
314  virtual services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
315 };
316 /* [Input source code] */
323 /* [Result source code] */
324 class DAAL_EXPORT Result : public optimization_solver::iterative_solver::Result
325 {
326 public:
327  DECLARE_SERIALIZABLE_CAST(Result);
328  typedef optimization_solver::iterative_solver::Result super;
329 
330  Result() {}
331  using super::set;
332  using super::get;
333 
342  template <typename algorithmFPType>
343  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, const int method);
344 
350  data_management::NumericTablePtr get(OptionalDataId id) const;
351 
357  void set(OptionalDataId id, const data_management::NumericTablePtr &ptr);
358 
367  virtual services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par,
368  int method) const DAAL_C11_OVERRIDE;
369 
370 };
371 typedef services::SharedPtr<Result> ResultPtr;
372 /* [Result source code] */
375 } // namespace interface1
376 using interface1::BaseParameter;
377 using interface1::Parameter;
378 using interface1::Input;
379 using interface1::Result;
380 using interface1::ResultPtr;
381 
382 } // namespace sgd
383 } // namespace optimization_solver
384 } // namespace algorithm
385 } // namespace daal
386 #endif
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter::engine
engines::EnginePtr engine
Definition: sgd_types.h:124
daal::algorithms::optimization_solver::sgd::interface1::Parameter< miniBatch >::conservativeSequence
data_management::NumericTablePtr conservativeSequence
Definition: sgd_types.h:221
daal
Definition: algorithm_base_common.h:31
daal::algorithms::optimization_solver::sgd::interface1::Parameter
Definition: sgd_types.h:130
daal::algorithms::optimization_solver::sgd::miniBatch
Definition: sgd_types.h:57
daal::algorithms::optimization_solver::sgd::interface1::Input
Input for the Stochastic gradient descent algorithm
Definition: sgd_types.h:284
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter::seed
size_t seed
Definition: sgd_types.h:122
daal::algorithms::em_gmm::nIterations
Definition: em_gmm_types.h:97
daal_defines.h
daal::algorithms::optimization_solver::sgd::OptionalDataId
OptionalDataId
Definition: sgd_types.h:65
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::defaultDense
Definition: sgd_types.h:56
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter::batchIndices
data_management::NumericTablePtr batchIndices
Definition: sgd_types.h:118
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter::learningRateSequence
data_management::NumericTablePtr learningRateSequence
Definition: sgd_types.h:121
daal::algorithms::optimization_solver::sgd::interface1::Parameter< momentum >::momentum
double momentum
Definition: sgd_types.h:272
daal::algorithms::optimization_solver::sgd::momentum
Definition: sgd_types.h:58
daal::algorithms::optimization_solver::sgd::pastUpdateVector
Definition: sgd_types.h:67
daal::algorithms::optimization_solver::sgd::Method
Method
Definition: sgd_types.h:54
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter
BaseParameter base class for the Stochastic gradient descent algorithm
Definition: sgd_types.h:85
daal::algorithms::optimization_solver::sgd::pastWorkValue
Definition: sgd_types.h:68

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