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

sgd_types.h
1 /* file: sgd_types.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 /*
43 //++
44 // Implementation of the Stochastic gradient descent algorithm types.
45 //--
46 */
47 
48 #ifndef __SGD_TYPES_H__
49 #define __SGD_TYPES_H__
50 
51 #include "algorithms/algorithm.h"
52 #include "data_management/data/numeric_table.h"
53 #include "data_management/data/homogen_numeric_table.h"
54 #include "services/daal_defines.h"
55 #include "algorithms/optimization_solver/iterative_solver/iterative_solver_types.h"
56 #include "algorithms/engines/mt19937/mt19937.h"
57 
58 namespace daal
59 {
60 namespace algorithms
61 {
62 namespace optimization_solver
63 {
73 namespace sgd
74 {
75 
80 enum Method
81 {
82  defaultDense = 0,
83  miniBatch = 1,
84  momentum = 2
85 };
86 
91 enum OptionalDataId
92 {
93  pastUpdateVector = iterative_solver::lastOptionalData + 1,
94  pastWorkValue = pastUpdateVector + 1 ,
95  lastOptionalData = pastWorkValue
96 };
97 
101 namespace interface1
102 {
103 
110 /* [BaseParameter source code] */
111 struct DAAL_EXPORT BaseParameter : public optimization_solver::iterative_solver::Parameter
112 {
124  BaseParameter(
125  const sum_of_functions::BatchPtr &function,
126  size_t nIterations = 100,
127  double accuracyThreshold = 1.0e-05,
128  data_management::NumericTablePtr batchIndices = data_management::NumericTablePtr(),
129  data_management::NumericTablePtr learningRateSequence = data_management::NumericTablePtr(
130  new data_management::HomogenNumericTable<double>(
131  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
132  size_t batchSize = 1,
133  size_t seed = 777 );
134 
135  virtual ~BaseParameter() {}
136 
142  virtual services::Status check() const;
143 
144  data_management::NumericTablePtr batchIndices;
147  data_management::NumericTablePtr learningRateSequence;
148  size_t seed;
150  engines::EnginePtr engine;
152 };
153 /* [BaseParameter source code] */
154 
155 template<Method method>
156 struct Parameter : public BaseParameter {};
157 
164 /* [ParameterDefaultDense source code] */
165 template<>
166 struct DAAL_EXPORT Parameter<defaultDense> : public BaseParameter
167 {
177  Parameter(
178  const sum_of_functions::BatchPtr &function,
179  size_t nIterations = 100,
180  double accuracyThreshold = 1.0e-05,
181  data_management::NumericTablePtr batchIndices = data_management::NumericTablePtr(),
182  data_management::NumericTablePtr learningRateSequence = data_management::NumericTablePtr(
183  new data_management::HomogenNumericTable<double>(
184  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
185  size_t seed = 777 );
186 
192  virtual services::Status check() const;
193 
194  virtual ~Parameter() {}
195 };
196 /* [ParameterDefaultDense source code] */
197 
204 /* [ParameterMiniBatch source code] */
205 template<>
206 struct DAAL_EXPORT Parameter<miniBatch> : public BaseParameter
207 {
223  Parameter(
224  const sum_of_functions::BatchPtr &function,
225  size_t nIterations = 100,
226  double accuracyThreshold = 1.0e-05,
227  data_management::NumericTablePtr batchIndices = data_management::NumericTablePtr(),
228  size_t batchSize = 128,
229  data_management::NumericTablePtr conservativeSequence = data_management::NumericTablePtr(
230  new data_management::HomogenNumericTable<double>(
231  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
232  size_t innerNIterations = 5,
233  data_management::NumericTablePtr learningRateSequence = data_management::NumericTablePtr(
234  new data_management::HomogenNumericTable<double>(
235  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
236  size_t seed = 777 );
237 
243  virtual services::Status check() const;
244 
245  virtual ~Parameter() {}
246 
247  data_management::NumericTablePtr conservativeSequence;
248  size_t innerNIterations;
249 };
250 /* [ParameterMiniBatch source code] */
259 /* [ParameterMomentum source code] */
260 template<>
261 struct DAAL_EXPORT Parameter<momentum> : public BaseParameter
262 {
277  Parameter(
278  const sum_of_functions::BatchPtr& function,
279  double momentum = 0.9,
280  size_t nIterations = 100,
281  double accuracyThreshold = 1.0e-05,
282  data_management::NumericTablePtr batchIndices = data_management::NumericTablePtr(),
283  size_t batchSize = 128,
284  data_management::NumericTablePtr learningRateSequence = data_management::NumericTablePtr(
285  new data_management::HomogenNumericTable<double>(
286  1, 1, data_management::NumericTableIface::doAllocate, 1.0)),
287  size_t seed = 777 );
288 
294  virtual services::Status check() const;
295 
296  virtual ~Parameter() {}
297 
298  double momentum;
299 };
300 /* [ParameterMomentum source code] */
309 /* [Input source code] */
310 class DAAL_EXPORT Input : public optimization_solver::iterative_solver::Input
311 {
312 public:
313  typedef optimization_solver::iterative_solver::Input super;
314  Input();
315  Input(const Input& other);
316  using super::set;
317  using super::get;
318 
324  data_management::NumericTablePtr get(OptionalDataId id) const;
325 
331  void set(OptionalDataId id, const data_management::NumericTablePtr &ptr);
332 
340  virtual services::Status check(const daal::algorithms::Parameter *par, int method) const DAAL_C11_OVERRIDE;
341 };
342 /* [Input source code] */
349 /* [Result source code] */
350 class DAAL_EXPORT Result : public optimization_solver::iterative_solver::Result
351 {
352 public:
353  DECLARE_SERIALIZABLE_CAST(Result);
354  typedef optimization_solver::iterative_solver::Result super;
355 
356  Result() {}
357  using super::set;
358  using super::get;
359 
368  template <typename algorithmFPType>
369  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par, const int method);
370 
376  data_management::NumericTablePtr get(OptionalDataId id) const;
377 
383  void set(OptionalDataId id, const data_management::NumericTablePtr &ptr);
384 
393  virtual services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *par,
394  int method) const DAAL_C11_OVERRIDE;
395 
396 };
397 typedef services::SharedPtr<Result> ResultPtr;
398 /* [Result source code] */
401 } // namespace interface1
402 using interface1::BaseParameter;
403 using interface1::Parameter;
404 using interface1::Input;
405 using interface1::Result;
406 using interface1::ResultPtr;
407 
408 } // namespace sgd
409 } // namespace optimization_solver
410 } // namespace algorithm
411 } // namespace daal
412 #endif
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter::engine
engines::EnginePtr engine
Definition: sgd_types.h:150
daal::algorithms::optimization_solver::sgd::interface1::Parameter< miniBatch >::conservativeSequence
data_management::NumericTablePtr conservativeSequence
Definition: sgd_types.h:247
daal
Definition: algorithm_base_common.h:57
daal::algorithms::optimization_solver::sgd::interface1::Parameter
Definition: sgd_types.h:156
daal::algorithms::optimization_solver::sgd::miniBatch
Definition: sgd_types.h:83
daal::algorithms::optimization_solver::sgd::interface1::Input
Input for the Stochastic gradient descent algorithm
Definition: sgd_types.h:310
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter::seed
size_t seed
Definition: sgd_types.h:148
daal::algorithms::em_gmm::nIterations
Definition: em_gmm_types.h:123
daal_defines.h
daal::algorithms::optimization_solver::sgd::OptionalDataId
OptionalDataId
Definition: sgd_types.h:91
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:350
daal::algorithms::optimization_solver::sgd::defaultDense
Definition: sgd_types.h:82
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter::batchIndices
data_management::NumericTablePtr batchIndices
Definition: sgd_types.h:144
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter::learningRateSequence
data_management::NumericTablePtr learningRateSequence
Definition: sgd_types.h:147
daal::algorithms::optimization_solver::sgd::interface1::Parameter< momentum >::momentum
double momentum
Definition: sgd_types.h:298
daal::algorithms::optimization_solver::sgd::momentum
Definition: sgd_types.h:84
daal::algorithms::optimization_solver::sgd::pastUpdateVector
Definition: sgd_types.h:93
daal::algorithms::optimization_solver::sgd::Method
Method
Definition: sgd_types.h:80
daal::algorithms::optimization_solver::sgd::interface1::BaseParameter
BaseParameter base class for the Stochastic gradient descent algorithm
Definition: sgd_types.h:111
daal::algorithms::optimization_solver::sgd::pastWorkValue
Definition: sgd_types.h:94

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