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

sgd_batch.h
1 /* file: sgd_batch.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 the stochastic gradient descent (SGD) algorithm
21 // in the batch processing mode
22 //--
23 */
24 
25 #ifndef __SGD_BATCH_H__
26 #define __SGD_BATCH_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "algorithms/optimization_solver/iterative_solver/iterative_solver_batch.h"
32 #include "sgd_types.h"
33 
34 namespace daal
35 {
36 namespace algorithms
37 {
38 namespace optimization_solver
39 {
40 namespace sgd
41 {
42 namespace interface1
43 {
57 template<typename algorithmFPType, Method method, CpuType cpu>
58 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
59 {
60 public:
66  DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv);
68  DAAL_DEPRECATED ~BatchContainer();
74  DAAL_DEPRECATED_VIRTUAL virtual services::Status compute() DAAL_C11_OVERRIDE;
75 };
76 
94 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
95 class DAAL_EXPORT Batch : public iterative_solver::interface1::Batch
96 {
97 public:
98  typedef algorithms::optimization_solver::sgd::interface1::Input InputType;
99  typedef algorithms::optimization_solver::sgd::interface1::Parameter<method> ParameterType;
100  typedef algorithms::optimization_solver::sgd::interface1::Result ResultType;
101 
102  InputType input;
103  Parameter<method> parameter;
109  DAAL_DEPRECATED Batch(const sum_of_functions::interface1::BatchPtr& objectiveFunction = sum_of_functions::interface1::BatchPtr()) :
110  input(),
111  parameter(objectiveFunction)
112  {
113  initialize();
114  }
115 
122  DAAL_DEPRECATED Batch(const Batch<algorithmFPType, method> &other) :
123  iterative_solver::interface1::Batch(other),
124  input(other.input),
125  parameter(other.parameter)
126  {
127  initialize();
128  }
129 
134  DAAL_DEPRECATED_VIRTUAL virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
135 
140  DAAL_DEPRECATED_VIRTUAL virtual iterative_solver::interface1::Input * getInput() DAAL_C11_OVERRIDE { return &input; }
141 
146  DAAL_DEPRECATED_VIRTUAL virtual iterative_solver::interface1::Parameter * getParameter() DAAL_C11_OVERRIDE { return &parameter; }
147 
153  DAAL_DEPRECATED_VIRTUAL virtual services::Status createResult() DAAL_C11_OVERRIDE
154  {
155  _result = iterative_solver::interface1::ResultPtr(new ResultType());
156  _res = NULL;
157  return services::Status();
158  }
159 
165  DAAL_DEPRECATED services::SharedPtr<Batch<algorithmFPType, method> > clone() const
166  {
167  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
168  }
169 
174  DAAL_DEPRECATED static services::SharedPtr<Batch<algorithmFPType, method> > create();
175 
176 protected:
177  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
178  {
179  return new Batch<algorithmFPType, method>(*this);
180  }
181 
182  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
183  {
184  services::Status s = static_cast<ResultType*>(_result.get())->allocate<algorithmFPType>(&input, &parameter, (int)method);
185  _res = _result.get();
186  return s;
187  }
188 
189  void initialize()
190  {
191  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
192  _par = &parameter;
193  _in = &input;
194  _result = iterative_solver::interface1::ResultPtr(new ResultType());
195  }
196 };
198 } // namespace interface1
199 
200 namespace interface2
201 {
215 template<typename algorithmFPType, Method method, CpuType cpu>
216 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
217 {
218 public:
224  BatchContainer(daal::services::Environment::env *daalEnv);
226  ~BatchContainer();
232  virtual services::Status compute() DAAL_C11_OVERRIDE;
233 };
234 
252 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
253 class DAAL_EXPORT Batch : public iterative_solver::Batch
254 {
255 public:
256  typedef algorithms::optimization_solver::sgd::Input InputType;
257  typedef algorithms::optimization_solver::sgd::Parameter<method> ParameterType;
258  typedef algorithms::optimization_solver::sgd::Result ResultType;
259 
260  InputType input;
261  Parameter<method> parameter;
267  Batch(const sum_of_functions::BatchPtr& objectiveFunction = sum_of_functions::BatchPtr()) :
268  input(),
269  parameter(objectiveFunction)
270  {
271  initialize();
272  }
273 
280  Batch(const Batch<algorithmFPType, method> &other) :
281  iterative_solver::Batch(other),
282  input(other.input),
283  parameter(other.parameter)
284  {
285  initialize();
286  }
287 
292  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
293 
298  virtual iterative_solver::Input * getInput() DAAL_C11_OVERRIDE { return &input; }
299 
304  virtual iterative_solver::Parameter * getParameter() DAAL_C11_OVERRIDE { return &parameter; }
305 
311  virtual services::Status createResult() DAAL_C11_OVERRIDE
312  {
313  _result = iterative_solver::ResultPtr(new ResultType());
314  _res = NULL;
315  return services::Status();
316  }
317 
323  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
324  {
325  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
326  }
327 
332  static services::SharedPtr<Batch<algorithmFPType, method> > create();
333 
334 protected:
335  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
336  {
337  return new Batch<algorithmFPType, method>(*this);
338  }
339 
340  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
341  {
342  services::Status s = static_cast<ResultType*>(_result.get())->allocate<algorithmFPType>(&input, &parameter, (int)method);
343  _res = _result.get();
344  return s;
345  }
346 
347  void initialize()
348  {
349  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
350  _par = &parameter;
351  _in = &input;
352  _result = iterative_solver::ResultPtr(new ResultType());
353  }
354 };
356 } // namespace interface2
357 
358 using interface2::BatchContainer;
359 using interface2::Batch;
360 
361 } // namespace sgd
362 } // namespace optimization_solver
363 } // namespace algorithm
364 } // namespace daal
365 #endif
daal::algorithms::optimization_solver::sgd::interface2::Batch::getInput
virtual iterative_solver::Input * getInput() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:298
daal::algorithms::optimization_solver::sgd::interface1::Batch::clone
DAAL_DEPRECATED services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: sgd_batch.h:165
daal::batch
Definition: daal_defines.h:112
daal::algorithms::optimization_solver::sgd::interface2::Batch::input
InputType input
Definition: sgd_batch.h:260
daal::algorithms::optimization_solver::iterative_solver::interface1::Batch
Interface for computing the iterative solver in the batch processing mode.
Definition: iterative_solver_batch.h:54
daal::algorithms::optimization_solver::sgd::interface2::Batch::createResult
virtual services::Status createResult() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:311
daal::algorithms::optimization_solver::sgd::interface2::Batch::Batch
Batch(const sum_of_functions::BatchPtr &objectiveFunction=sum_of_functions::BatchPtr())
Definition: sgd_batch.h:267
daal::algorithms::optimization_solver::sgd::interface1::Batch::input
InputType input
Definition: sgd_batch.h:102
daal::algorithms::optimization_solver::sgd::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: sgd_batch.h:280
daal::algorithms::optimization_solver::sgd::interface2::Batch
Computes Stochastic gradient descent in the batch processing mode.
Definition: sgd_batch.h:253
daal::algorithms::optimization_solver::sgd::interface1::Batch::getInput
virtual DAAL_DEPRECATED_VIRTUAL iterative_solver::interface1::Input * getInput() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:140
daal::algorithms::optimization_solver::sgd::interface1::Batch::Batch
DAAL_DEPRECATED Batch(const Batch< algorithmFPType, method > &other)
Definition: sgd_batch.h:122
daal::algorithms::optimization_solver::sgd::interface2::Parameter
Definition: sgd_types.h:438
daal::algorithms::optimization_solver::sgd::interface2::BatchContainer::~BatchContainer
~BatchContainer()
daal::algorithms::AnalysisContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the analy...
Definition: analysis.h:55
daal::algorithms::optimization_solver::sgd::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal_defines.h
daal::algorithms::optimization_solver::sgd::interface2::Batch::getParameter
virtual iterative_solver::Parameter * getParameter() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:304
daal::algorithms::optimization_solver::sgd::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: sgd_batch.h:323
daal::algorithms::optimization_solver::sgd::interface1::BatchContainer::compute
virtual DAAL_DEPRECATED_VIRTUAL services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::optimization_solver::sgd::interface1::Batch::getParameter
virtual DAAL_DEPRECATED_VIRTUAL iterative_solver::interface1::Parameter * getParameter() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:146
daal::algorithms::optimization_solver::sgd::interface1::Batch::Batch
DAAL_DEPRECATED Batch(const sum_of_functions::interface1::BatchPtr &objectiveFunction=sum_of_functions::interface1::BatchPtr())
Definition: sgd_batch.h:109
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:216
daal::algorithms::optimization_solver::sgd::interface1::BatchContainer::~BatchContainer
DAAL_DEPRECATED ~BatchContainer()
daal::algorithms::optimization_solver::sgd::interface1::Input
Input for the Stochastic gradient descent algorithm
Definition: sgd_types.h:286
daal::algorithms::optimization_solver::iterative_solver::interface1::Input
Input parameters for the iterative solver algorithm
Definition: iterative_solver_types.h:160
daal::algorithms::optimization_solver::sgd::interface1::Batch::parameter
Parameter< method > parameter
Definition: sgd_batch.h:103
daal::algorithms::optimization_solver::sgd::interface2::Batch::parameter
Parameter< method > parameter
Definition: sgd_batch.h:261
daal::algorithms::optimization_solver::sgd::interface1::Batch
Computes Stochastic gradient descent in the batch processing mode.
Definition: sgd_batch.h:95
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:58
daal::algorithms::optimization_solver::sgd::interface2::BatchContainer::compute
virtual services::Status compute() DAAL_C11_OVERRIDE
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:326
daal::algorithms::Analysis
Provides methods for execution of operations over data, such as computation of Summary Statistics est...
Definition: analysis.h:70
daal::algorithms::optimization_solver::sgd::interface1::Batch::getMethod
virtual DAAL_DEPRECATED_VIRTUAL int getMethod() const DAAL_C11_OVERRIDE
Definition: sgd_batch.h:134
daal::algorithms::optimization_solver::sgd::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: sgd_batch.h:292
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:223
daal::algorithms::optimization_solver::sgd::interface1::Parameter
Definition: sgd_types.h:132
daal::algorithms::optimization_solver::iterative_solver::interface1::Parameter
Parameter base class for the iterative solver algorithm
Definition: iterative_solver_types.h:115
daal::algorithms::optimization_solver::sgd::interface1::Batch::createResult
virtual DAAL_DEPRECATED_VIRTUAL services::Status createResult() DAAL_C11_OVERRIDE
Definition: sgd_batch.h:153
daal::algorithms::optimization_solver::sgd::interface1::BatchContainer::BatchContainer
DAAL_DEPRECATED BatchContainer(daal::services::Environment::env *daalEnv)

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