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

linear_regression_training_distributed.h
1 /* file: linear_regression_training_distributed.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 linear regression model-based training
19 // in the distributed processing mode
20 //--
21 */
22 
23 #ifndef __LINEAR_REGRESSION_TRAINING_DISTRIBUTED_H__
24 #define __LINEAR_REGRESSION_TRAINING_DISTRIBUTED_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "data_management/data/numeric_table.h"
28 #include "services/daal_defines.h"
29 #include "services/daal_memory.h"
30 #include "algorithms/linear_regression/linear_regression_training_types.h"
31 #include "algorithms/linear_regression/linear_regression_training_online.h"
32 
33 #include "algorithms/linear_regression/linear_regression_model.h"
34 
35 namespace daal
36 {
37 namespace algorithms
38 {
39 namespace linear_regression
40 {
41 namespace training
42 {
43 
44 namespace interface1
45 {
55 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
56 class DAAL_EXPORT DistributedContainer
57 {};
58 
64 template<typename algorithmFPType, Method method, CpuType cpu>
65 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public
66  TrainingContainerIface<distributed>
67 {
68 public:
74  DistributedContainer(daal::services::Environment::env *daalEnv);
76  ~DistributedContainer();
77 
84  services::Status compute() DAAL_C11_OVERRIDE;
91  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
92 };
93 
113 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = normEqDense>
114 class DAAL_EXPORT Distributed : public Training<distributed> {};
115 
135 template<typename algorithmFPType, Method method>
136 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
137 {
138 public:
139  typedef Online<algorithmFPType, method> super;
140 
141  typedef typename super::InputType InputType;
142  typedef typename super::ParameterType ParameterType;
143  typedef typename super::ResultType ResultType;
144  typedef typename super::PartialResultType PartialResultType;
145 
147  Distributed<step1Local, algorithmFPType, method>()
148  {}
149 
156  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
157  Online<algorithmFPType, method>(other)
158  {}
159 
166  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
167  {
168  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
169  }
170 
171 protected:
172  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
173  {
174  return new Distributed<step1Local, algorithmFPType, method>(*this);
175  }
176 };
177 
195 template<typename algorithmFPType, Method method>
196 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
197 {
198 public:
199  typedef algorithms::linear_regression::training::DistributedInput<step2Master> InputType;
200  typedef algorithms::linear_regression::Parameter ParameterType;
201  typedef algorithms::linear_regression::training::Result ResultType;
202  typedef algorithms::linear_regression::training::PartialResult PartialResultType;
203 
205  Distributed()
206  {
207  initialize();
208  }
209 
216  Distributed(const Distributed<step2Master, algorithmFPType, method> &other)
217  {
218  initialize();
219  input.set(partialModels, other.input.get(partialModels));
220  parameter = other.parameter;
221  }
222 
223  ~Distributed() {}
224 
229  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
230 
237  services::Status setPartialResult(const PartialResultPtr& partialResult)
238  {
239  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
240  _partialResult = partialResult;
241  _pres = _partialResult.get();
242  return services::Status();
243  }
244 
249  PartialResultPtr getPartialResult() { return _partialResult; }
250 
257  services::Status setResult(const ResultPtr& res)
258  {
259  DAAL_CHECK(res, services::ErrorNullResult)
260  _result = res;
261  _res = _result.get();
262  return services::Status();
263  }
264 
271  ResultPtr getResult() { return _result; }
272 
279  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
280  {
281  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
282  }
283 
284  DistributedInput<step2Master> input;
285  ParameterType parameter;
287 protected:
288  PartialResultPtr _partialResult;
289  ResultPtr _result;
290 
291  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
292  {
293  return new Distributed<step2Master, algorithmFPType, method>(*this);
294  }
295 
296  services::Status allocateResult() DAAL_C11_OVERRIDE
297  {
298  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, method);
299  _res = _result.get();
300  return s;
301  }
302 
303  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
304  {
305  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
306  _pres = _partialResult.get();
307  return s;
308  }
309 
310  services::Status initializePartialResult() DAAL_C11_OVERRIDE
311  {
312  return services::Status();
313  }
314 
315  void initialize()
316  {
317  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
318  _in = &input;
319  _par = &parameter;
320  _partialResult.reset(new PartialResultType());
321  _result.reset(new ResultType());
322  }
323 
324 }; // class : public Training
326 } // namespace interface1
327 using interface1::DistributedContainer;
328 using interface1::Distributed;
329 
330 }
331 }
332 }
333 }
334 #endif
daal::algorithms::linear_regression::training::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: linear_regression_training_distributed.h:166
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: linear_regression_training_distributed.h:285
daal
Definition: algorithm_base_common.h:31
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: linear_regression_training_distributed.h:216
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: linear_regression_training_distributed.h:279
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:105
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: linear_regression_training_distributed.h:205
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: linear_regression_training_distributed.h:249
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: linear_regression_training_distributed.h:257
daal_defines.h
daal::algorithms::linear_regression::training::interface1::DistributedInput< step2Master >
Input object for linear regression model-based training in the second step of the distributed process...
Definition: linear_regression_training_types.h:281
daal::algorithms::kmeans::init::interface1::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for the K-Means algorithm in the distributed processing mode...
Definition: kmeans_init_distributed.h:255
daal::distributed
Definition: daal_defines.h:107
daal::algorithms::linear_regression::training::partialModels
Definition: linear_regression_training_types.h:79
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: linear_regression_training_distributed.h:271
daal::algorithms::linear_regression::training::interface1::Distributed
Provides methods for linear regression model-based training in the distributed processing mode...
Definition: linear_regression_training_distributed.h:114
daal::algorithms::linear_regression::training::interface1::DistributedContainer
Class containing methods for linear regression model-based training in the distributed processing mod...
Definition: linear_regression_training_distributed.h:56
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: linear_regression_training_distributed.h:237
daal::algorithms::linear_regression::training::interface1::DistributedInput< step2Master >::get
data_management::DataCollectionPtr get(Step2MasterInputId id) const
daal::algorithms::linear_regression::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: linear_regression_training_distributed.h:156
daal::algorithms::linear_regression::training::interface1::Distributed< step1Local, algorithmFPType, method >
Performs linear regression model-based training in the the first step of the distributed processing m...
Definition: linear_regression_training_distributed.h:136
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: linear_regression_training_distributed.h:284
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >
Performs linear regression model-based training in the the second step of distributed processing mode...
Definition: linear_regression_training_distributed.h:196
daal::algorithms::kmeans::interface1::DistributedContainer
class DAAL_EXPORT DistributedContainer
Provides methods to run implementations of the K-Means algorithm. This class is associated with the d...
Definition: kmeans_distributed.h:55
daal::step1Local
Definition: daal_defines.h:117
daal::step2Master
Definition: daal_defines.h:118
daal::algorithms::linear_regression::training::interface1::Online
Provides methods for linear regression model-based training in the online processing mode...
Definition: linear_regression_training_online.h:99
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:50
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:60
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: linear_regression_training_distributed.h:229

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