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

sgd_batch.h
1 /* file: sgd_batch.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 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::Batch
94 {
95 public:
96  typedef algorithms::optimization_solver::sgd::Input InputType;
97  typedef algorithms::optimization_solver::sgd::Parameter<method> ParameterType;
98  typedef algorithms::optimization_solver::sgd::Result ResultType;
99 
100  InputType input;
101  Parameter<method> parameter;
107  Batch(const sum_of_functions::BatchPtr& objectiveFunction = sum_of_functions::BatchPtr()) :
108  input(),
109  parameter(objectiveFunction)
110  {
111  initialize();
112  }
113 
120  Batch(const Batch<algorithmFPType, method> &other) :
121  iterative_solver::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::Input * getInput() DAAL_C11_OVERRIDE { return &input; }
139 
144  virtual iterative_solver::Parameter * getParameter() DAAL_C11_OVERRIDE { return &parameter; }
145 
151  virtual services::Status createResult() DAAL_C11_OVERRIDE
152  {
153  _result = iterative_solver::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 
168 protected:
169  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
170  {
171  return new Batch<algorithmFPType, method>(*this);
172  }
173 
174  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
175  {
176  services::Status s = static_cast<ResultType*>(_result.get())->allocate<algorithmFPType>(&input, &parameter, (int)method);
177  _res = _result.get();
178  return s;
179  }
180 
181  void initialize()
182  {
183  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
184  _par = &parameter;
185  _in = &input;
186  _result = iterative_solver::ResultPtr(new ResultType());
187  }
188 };
190 } // namespace interface1
191 using interface1::BatchContainer;
192 using interface1::Batch;
193 
194 } // namespace sgd
195 } // namespace optimization_solver
196 } // namespace algorithm
197 } // namespace daal
198 #endif
daal::algorithms::optimization_solver::sgd::interface1::Batch::input
InputType input
Definition: sgd_batch.h:100
daal::algorithms::optimization_solver::sgd::interface1::Batch::Batch
Batch(const sum_of_functions::BatchPtr &objectiveFunction=sum_of_functions::BatchPtr())
Definition: sgd_batch.h:107
daal
Definition: algorithm_base_common.h:31
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::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::interface1::Batch::getParameter
virtual iterative_solver::Parameter * getParameter() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:144
daal_defines.h
daal::batch
Definition: daal_defines.h:106
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::interface1::Batch::parameter
Parameter< method > parameter
Definition: sgd_batch.h:101
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::interface1::Batch::getInput
virtual iterative_solver::Input * getInput() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:138
daal::algorithms::optimization_solver::sgd::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: sgd_batch.h:163
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::iterative_solver::interface1::Batch
Interface for computing the iterative solver in the batch processing mode.
Definition: iterative_solver_batch.h:52
daal::algorithms::kmeans::objectiveFunction
Definition: kmeans_types.h:109

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