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

linear_regression_training_distributed.h
1 /* file: linear_regression_training_distributed.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 linear regression model-based training
21 // in the distributed processing mode
22 //--
23 */
24 
25 #ifndef __LINEAR_REGRESSION_TRAINING_DISTRIBUTED_H__
26 #define __LINEAR_REGRESSION_TRAINING_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "data_management/data/numeric_table.h"
30 #include "services/daal_defines.h"
31 #include "services/daal_memory.h"
32 #include "algorithms/linear_regression/linear_regression_training_types.h"
33 #include "algorithms/linear_regression/linear_regression_training_online.h"
34 
35 #include "algorithms/linear_regression/linear_regression_model.h"
36 
37 namespace daal
38 {
39 namespace algorithms
40 {
41 namespace linear_regression
42 {
43 namespace training
44 {
45 
46 namespace interface1
47 {
57 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
58 class DistributedContainer
59 {};
60 
66 template<typename algorithmFPType, Method method, CpuType cpu>
67 class DistributedContainer<step2Master, algorithmFPType, method, cpu> : public
68  TrainingContainerIface<distributed>
69 {
70 public:
76  DistributedContainer(daal::services::Environment::env *daalEnv);
78  ~DistributedContainer();
79 
86  services::Status compute() DAAL_C11_OVERRIDE;
93  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
94 };
95 
115 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = normEqDense>
116 class DAAL_EXPORT Distributed : public Training<distributed> {};
117 
137 template<typename algorithmFPType, Method method>
138 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
139 {
140 public:
141  typedef Online<algorithmFPType, method> super;
142 
143  typedef typename super::InputType InputType;
144  typedef typename super::ParameterType ParameterType;
145  typedef typename super::ResultType ResultType;
146  typedef typename super::PartialResultType PartialResultType;
147 
149  Distributed<step1Local, algorithmFPType, method>()
150  {}
151 
158  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
159  Online<algorithmFPType, method>(other)
160  {}
161 
168  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
169  {
170  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
171  }
172 
173 protected:
174  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
175  {
176  return new Distributed<step1Local, algorithmFPType, method>(*this);
177  }
178 };
179 
197 template<typename algorithmFPType, Method method>
198 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
199 {
200 public:
201  typedef algorithms::linear_regression::training::DistributedInput<step2Master> InputType;
202  typedef algorithms::linear_regression::Parameter ParameterType;
203  typedef algorithms::linear_regression::training::Result ResultType;
204  typedef algorithms::linear_regression::training::PartialResult PartialResultType;
205 
207  Distributed()
208  {
209  initialize();
210  }
211 
218  Distributed(const Distributed<step2Master, algorithmFPType, method> &other)
219  {
220  initialize();
221  input.set(partialModels, other.input.get(partialModels));
222  parameter = other.parameter;
223  }
224 
225  ~Distributed() {}
226 
231  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
232 
239  services::Status setPartialResult(const PartialResultPtr& partialResult)
240  {
241  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
242  _partialResult = partialResult;
243  _pres = _partialResult.get();
244  return services::Status();
245  }
246 
251  PartialResultPtr getPartialResult() { return _partialResult; }
252 
259  services::Status setResult(const ResultPtr& res)
260  {
261  DAAL_CHECK(res, services::ErrorNullResult)
262  _result = res;
263  _res = _result.get();
264  return services::Status();
265  }
266 
273  ResultPtr getResult() { return _result; }
274 
281  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
282  {
283  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
284  }
285 
286  DistributedInput<step2Master> input;
287  ParameterType parameter;
289 protected:
290  PartialResultPtr _partialResult;
291  ResultPtr _result;
292 
293  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
294  {
295  return new Distributed<step2Master, algorithmFPType, method>(*this);
296  }
297 
298  services::Status allocateResult() DAAL_C11_OVERRIDE
299  {
300  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, method);
301  _res = _result.get();
302  return s;
303  }
304 
305  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
306  {
307  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
308  _pres = _partialResult.get();
309  return s;
310  }
311 
312  services::Status initializePartialResult() DAAL_C11_OVERRIDE
313  {
314  return services::Status();
315  }
316 
317  void initialize()
318  {
319  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
320  _in = &input;
321  _par = &parameter;
322  _partialResult.reset(new PartialResultType());
323  _result.reset(new ResultType());
324  }
325 
326 }; // class : public Training
328 } // namespace interface1
329 using interface1::DistributedContainer;
330 using interface1::Distributed;
331 
332 }
333 }
334 }
335 }
336 #endif
daal::step1Local
Definition: daal_defines.h:123
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:281
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:283
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: linear_regression_training_distributed.h:286
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: linear_regression_training_distributed.h:287
daal::step2Master
Definition: daal_defines.h:124
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:58
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:198
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: linear_regression_training_distributed.h:259
daal::algorithms::kmeans::init::interface2::Distributed
class DAAL_EXPORT Distributed
Computes initial clusters for K-Means algorithm in the distributed processing mode.
Definition: kmeans_init_distributed.h:277
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:168
daal_defines.h
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: linear_regression_training_distributed.h:207
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:116
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:62
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: linear_regression_training_distributed.h:218
daal::algorithms::linear_regression::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: linear_regression_training_distributed.h:158
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:138
daal::algorithms::linear_regression::training::interface1::DistributedInput< step2Master >::get
data_management::DataCollectionPtr get(Step2MasterInputId id) const
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
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:101
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: linear_regression_training_distributed.h:231
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: linear_regression_training_distributed.h:251
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::linear_regression::training::partialModels
Definition: linear_regression_training_types.h:81
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: linear_regression_training_distributed.h:239
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: linear_regression_training_distributed.h:273

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