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

lbfgs_batch.h
1 /* file: lbfgs_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 limited-memory Broyden-Fletcher-Goldfarb-Shanno
21 // (BFGS) algorithm in the batch processing mode
22 //--
23 */
24 
25 #ifndef __LBFGS_BATCH_H__
26 #define __LBFGS_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 "lbfgs_types.h"
33 
34 namespace daal
35 {
36 namespace algorithms
37 {
38 namespace optimization_solver
39 {
40 namespace lbfgs
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  BatchContainer(daal::services::Environment::env *daalEnv);
68  ~BatchContainer();
74  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::lbfgs::interface1::Input InputType;
99  typedef algorithms::optimization_solver::lbfgs::interface1::Parameter ParameterType;
100  typedef algorithms::optimization_solver::lbfgs::interface1::Result ResultType;
101 
102  InputType input;
103  ParameterType parameter;
109  Batch(const sum_of_functions::interface1::BatchPtr& objectiveFunction = sum_of_functions::interface1::BatchPtr()) :
110  input(),
111  parameter(objectiveFunction)
112  {
113  initialize();
114  }
115 
121  Batch(const Batch<algorithmFPType, method> &other) :
122  iterative_solver::interface1::Batch(other),
123  input(other.input),
124  parameter(other.parameter)
125  {
126  initialize();
127  }
128 
133  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int) method; }
134 
139  virtual iterative_solver::interface1::Input * getInput() DAAL_C11_OVERRIDE { return &input; }
140 
145  virtual iterative_solver::interface1::Parameter * getParameter() DAAL_C11_OVERRIDE { return &parameter; }
146 
152  virtual services::Status createResult() DAAL_C11_OVERRIDE
153  {
154  _result = iterative_solver::interface1::ResultPtr(new ResultType());
155  _res = NULL;
156  return services::Status();
157  }
158 
164  services::SharedPtr<Batch<algorithmFPType, method> > clone() const
165  {
166  return services::SharedPtr<Batch<algorithmFPType, method> >(cloneImpl());
167  }
168 
173  static services::SharedPtr<Batch<algorithmFPType, method> > create();
174 
175 protected:
176  virtual Batch<algorithmFPType, method> *cloneImpl() const DAAL_C11_OVERRIDE
177  {
178  return new Batch<algorithmFPType, method>(*this);
179  }
180 
181  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
182  {
183  services::Status s = static_cast<ResultType*>(_result.get())->allocate<algorithmFPType>(&input, &parameter, (int)method);
184  _res = _result.get();
185  return s;
186  }
187 
188  void initialize()
189  {
190  Analysis<batch>::_ac = new __DAAL_ALGORITHM_CONTAINER(batch, BatchContainer, algorithmFPType, method)(&_env);
191  _par = &parameter;
192  _in = &input;
193  _result.reset(new ResultType());
194  }
195 };
197 } // namespace interface1
198 
199 namespace interface2
200 {
214 template<typename algorithmFPType, Method method, CpuType cpu>
215 class BatchContainer : public daal::algorithms::AnalysisContainerIface<batch>
216 {
217 public:
223  BatchContainer(daal::services::Environment::env *daalEnv);
225  ~BatchContainer();
231  virtual services::Status compute() DAAL_C11_OVERRIDE;
232 };
233 
251 template<typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
252 class DAAL_EXPORT Batch : public iterative_solver::Batch
253 {
254 public:
255  typedef algorithms::optimization_solver::lbfgs::Input InputType;
256  typedef algorithms::optimization_solver::lbfgs::Parameter ParameterType;
257  typedef algorithms::optimization_solver::lbfgs::Result ResultType;
258 
259  InputType input;
260  ParameterType parameter;
266  Batch(const sum_of_functions::BatchPtr& objectiveFunction = sum_of_functions::BatchPtr()) :
267  input(),
268  parameter(objectiveFunction)
269  {
270  initialize();
271  }
272 
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.reset(new ResultType());
351  }
352 };
354 } // namespace interface2
355 using interface2::BatchContainer;
356 using interface2::Batch;
357 
358 } // namespace lbfgs
359 } // namespace optimization_solver
360 } // namespace algorithm
361 } // namespace daal
362 
363 #endif
daal::algorithms::optimization_solver::lbfgs::interface1::BatchContainer::compute
virtual services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::optimization_solver::lbfgs::interface1::Batch::Batch
Batch(const sum_of_functions::interface1::BatchPtr &objectiveFunction=sum_of_functions::interface1::BatchPtr())
Definition: lbfgs_batch.h:109
daal::batch
Definition: daal_defines.h:112
daal::algorithms::optimization_solver::lbfgs::interface1::BatchContainer::~BatchContainer
~BatchContainer()
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::lbfgs::interface2::Batch::Batch
Batch(const sum_of_functions::BatchPtr &objectiveFunction=sum_of_functions::BatchPtr())
Definition: lbfgs_batch.h:266
daal::algorithms::optimization_solver::lbfgs::interface2::Batch::getInput
virtual iterative_solver::Input * getInput() DAAL_C11_OVERRIDE
Definition: lbfgs_batch.h:296
daal::algorithms::optimization_solver::lbfgs::interface2::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: lbfgs_batch.h:321
daal::algorithms::optimization_solver::lbfgs::interface2::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: lbfgs_batch.h:278
daal::algorithms::optimization_solver::lbfgs::interface1::BatchContainer
Provides methods to run implementations of the LBFGS algorithm. This class is associated with daal::a...
Definition: lbfgs_batch.h:58
daal::algorithms::optimization_solver::lbfgs::interface2::BatchContainer::compute
virtual services::Status compute() DAAL_C11_OVERRIDE
daal::algorithms::optimization_solver::lbfgs::interface1::Batch::getParameter
virtual iterative_solver::interface1::Parameter * getParameter() DAAL_C11_OVERRIDE
Definition: lbfgs_batch.h:145
daal::algorithms::optimization_solver::lbfgs::interface2::Batch
Computes LBFGS in the batch processing mode.
Definition: lbfgs_batch.h:252
daal::algorithms::optimization_solver::lbfgs::interface1::Batch::clone
services::SharedPtr< Batch< algorithmFPType, method > > clone() const
Definition: lbfgs_batch.h:164
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::lbfgs::interface1::Batch::Batch
Batch(const Batch< algorithmFPType, method > &other)
Definition: lbfgs_batch.h:121
daal::algorithms::optimization_solver::lbfgs::interface1::Batch::parameter
ParameterType parameter
Definition: lbfgs_batch.h:103
daal_defines.h
daal::algorithms::optimization_solver::lbfgs::interface1::Batch::getInput
virtual iterative_solver::interface1::Input * getInput() DAAL_C11_OVERRIDE
Definition: lbfgs_batch.h:139
daal::algorithms::optimization_solver::lbfgs::interface2::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: lbfgs_batch.h:290
daal::algorithms::optimization_solver::lbfgs::interface1::Parameter
Parameter class for LBFGS algorithm
Definition: lbfgs_types.h:104
daal::algorithms::optimization_solver::lbfgs::interface1::Input
Input class for LBFGS algorithm
Definition: lbfgs_types.h:158
daal::algorithms::optimization_solver::lbfgs::interface2::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::optimization_solver::lbfgs::interface2::Batch::parameter
ParameterType parameter
Definition: lbfgs_batch.h:260
daal::algorithms::optimization_solver::lbfgs::interface2::BatchContainer::~BatchContainer
~BatchContainer()
daal::algorithms::optimization_solver::lbfgs::interface2::BatchContainer
Provides methods to run implementations of the LBFGS algorithm. This class is associated with daal::a...
Definition: lbfgs_batch.h:215
daal::algorithms::optimization_solver::lbfgs::interface1::Batch::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: lbfgs_batch.h:133
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::lbfgs::interface2::Batch::getParameter
virtual iterative_solver::Parameter * getParameter() DAAL_C11_OVERRIDE
Definition: lbfgs_batch.h:302
daal::algorithms::optimization_solver::lbfgs::interface2::Batch::createResult
virtual services::Status createResult() DAAL_C11_OVERRIDE
Definition: lbfgs_batch.h:309
daal::algorithms::optimization_solver::lbfgs::interface1::Result
Results obtained with the compute() method of the LBFGS algorithm in the batch processing mode...
Definition: lbfgs_types.h:196
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::lbfgs::interface1::Batch::input
InputType input
Definition: lbfgs_batch.h:102
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::lbfgs::interface1::Batch::createResult
virtual services::Status createResult() DAAL_C11_OVERRIDE
Definition: lbfgs_batch.h:152
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::lbfgs::interface2::Batch::input
InputType input
Definition: lbfgs_batch.h:259
daal::algorithms::optimization_solver::lbfgs::interface1::BatchContainer::BatchContainer
BatchContainer(daal::services::Environment::env *daalEnv)
daal::algorithms::optimization_solver::lbfgs::interface1::Batch
Computes LBFGS in the batch processing mode.
Definition: lbfgs_batch.h:95

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