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

linear_regression_training_distributed.h
1 /* file: linear_regression_training_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation
4 * All Rights Reserved.
5 *
6 * If this software was obtained under the Intel Simplified Software License,
7 * the following terms apply:
8 *
9 * The source code, information and material ("Material") contained herein is
10 * owned by Intel Corporation or its suppliers or licensors, and title to such
11 * Material remains with Intel Corporation or its suppliers or licensors. The
12 * Material contains proprietary information of Intel or its suppliers and
13 * licensors. The Material is protected by worldwide copyright laws and treaty
14 * provisions. No part of the Material may be used, copied, reproduced,
15 * modified, published, uploaded, posted, transmitted, distributed or disclosed
16 * in any way without Intel's prior express written permission. No license under
17 * any patent, copyright or other intellectual property rights in the Material
18 * is granted to or conferred upon you, either expressly, by implication,
19 * inducement, estoppel or otherwise. Any license under such intellectual
20 * property rights must be express and approved by Intel in writing.
21 *
22 * Unless otherwise agreed by Intel in writing, you may not remove or alter this
23 * notice or any other notice embedded in Materials by Intel or Intel's
24 * suppliers or licensors in any way.
25 *
26 *
27 * If this software was obtained under the Apache License, Version 2.0 (the
28 * "License"), the following terms apply:
29 *
30 * You may not use this file except in compliance with the License. You may
31 * obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
32 *
33 *
34 * Unless required by applicable law or agreed to in writing, software
35 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
36 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
37 *
38 * See the License for the specific language governing permissions and
39 * limitations under the License.
40 *******************************************************************************/
41 
42 /*
43 //++
44 // Implementation of the interface for linear regression model-based training
45 // in the distributed processing mode
46 //--
47 */
48 
49 #ifndef __LINEAR_REGRESSION_TRAINING_DISTRIBUTED_H__
50 #define __LINEAR_REGRESSION_TRAINING_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "data_management/data/numeric_table.h"
54 #include "services/daal_defines.h"
55 #include "services/daal_memory.h"
56 #include "algorithms/linear_regression/linear_regression_training_types.h"
57 #include "algorithms/linear_regression/linear_regression_training_online.h"
58 
59 #include "algorithms/linear_regression/linear_regression_model.h"
60 
61 namespace daal
62 {
63 namespace algorithms
64 {
65 namespace linear_regression
66 {
67 namespace training
68 {
69 
70 namespace interface1
71 {
81 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
82 class DAAL_EXPORT DistributedContainer
83 {};
84 
90 template<typename algorithmFPType, Method method, CpuType cpu>
91 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public
92  TrainingContainerIface<distributed>
93 {
94 public:
100  DistributedContainer(daal::services::Environment::env *daalEnv);
102  ~DistributedContainer();
103 
110  services::Status compute() DAAL_C11_OVERRIDE;
117  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
118 };
119 
139 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = normEqDense>
140 class DAAL_EXPORT Distributed : public Training<distributed> {};
141 
161 template<typename algorithmFPType, Method method>
162 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
163 {
164 public:
165  typedef Online<algorithmFPType, method> super;
166 
167  typedef typename super::InputType InputType;
168  typedef typename super::ParameterType ParameterType;
169  typedef typename super::ResultType ResultType;
170  typedef typename super::PartialResultType PartialResultType;
171 
173  Distributed<step1Local, algorithmFPType, method>()
174  {}
175 
182  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) :
183  Online<algorithmFPType, method>(other)
184  {}
185 
192  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
193  {
194  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
195  }
196 
197 protected:
198  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
199  {
200  return new Distributed<step1Local, algorithmFPType, method>(*this);
201  }
202 };
203 
221 template<typename algorithmFPType, Method method>
222 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
223 {
224 public:
225  typedef algorithms::linear_regression::training::DistributedInput<step2Master> InputType;
226  typedef algorithms::linear_regression::Parameter ParameterType;
227  typedef algorithms::linear_regression::training::Result ResultType;
228  typedef algorithms::linear_regression::training::PartialResult PartialResultType;
229 
231  Distributed()
232  {
233  initialize();
234  }
235 
242  Distributed(const Distributed<step2Master, algorithmFPType, method> &other)
243  {
244  initialize();
245  input.set(partialModels, other.input.get(partialModels));
246  parameter = other.parameter;
247  }
248 
249  ~Distributed() {}
250 
255  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
256 
263  services::Status setPartialResult(const PartialResultPtr& partialResult)
264  {
265  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
266  _partialResult = partialResult;
267  _pres = _partialResult.get();
268  return services::Status();
269  }
270 
275  PartialResultPtr getPartialResult() { return _partialResult; }
276 
283  services::Status setResult(const ResultPtr& res)
284  {
285  DAAL_CHECK(res, services::ErrorNullResult)
286  _result = res;
287  _res = _result.get();
288  return services::Status();
289  }
290 
297  ResultPtr getResult() { return _result; }
298 
305  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
306  {
307  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
308  }
309 
310  DistributedInput<step2Master> input;
311  ParameterType parameter;
313 protected:
314  PartialResultPtr _partialResult;
315  ResultPtr _result;
316 
317  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
318  {
319  return new Distributed<step2Master, algorithmFPType, method>(*this);
320  }
321 
322  services::Status allocateResult() DAAL_C11_OVERRIDE
323  {
324  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, method);
325  _res = _result.get();
326  return s;
327  }
328 
329  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
330  {
331  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
332  _pres = _partialResult.get();
333  return s;
334  }
335 
336  services::Status initializePartialResult() DAAL_C11_OVERRIDE
337  {
338  return services::Status();
339  }
340 
341  void initialize()
342  {
343  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
344  _in = &input;
345  _par = &parameter;
346  _partialResult.reset(new PartialResultType());
347  _result.reset(new ResultType());
348  }
349 
350 }; // class : public Training
352 } // namespace interface1
353 using interface1::DistributedContainer;
354 using interface1::Distributed;
355 
356 }
357 }
358 }
359 }
360 #endif
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: linear_regression_training_distributed.h:311
daal::services::interface1::Environment::_envStruct
The environment structure.
Definition: env_detect.h:95
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
daal
Definition: algorithm_base_common.h:57
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: linear_regression_training_distributed.h:242
daal::algorithms::linear_regression::training::interface1::DistributedInput< step2Master >::get
data_management::DataCollectionPtr get(Step2MasterInputId id) const
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:305
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
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:275
daal::algorithms::linear_model::training::interface1::Result
Provides methods to access the result obtained with the compute() method of the regression model-base...
Definition: linear_model_training_types.h:174
daal::algorithms::linear_model::interface1::Parameter
Parameters for the regression algorithm.
Definition: linear_model_model.h:85
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: linear_regression_training_distributed.h:283
daal_defines.h
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:192
daal::algorithms::linear_model::training::interface1::Input
Input objects for the regression model-based training
Definition: linear_model_training_types.h:103
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:307
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:281
daal::distributed
Definition: daal_defines.h:133
daal::algorithms::linear_regression::training::partialModels
Definition: linear_regression_training_types.h:105
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: linear_regression_training_distributed.h:297
daal::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::algorithms::linear_regression::training::interface1::DistributedInput
Input object for linear regression model-based training in the distributed processing mode ...
Definition: linear_regression_training_types.h:210
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:140
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:82
daal::algorithms::linear_regression::training::interface1::Result
Provides methods to access the result obtained with the compute() method of linear regression model-b...
Definition: linear_regression_training_types.h:361
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: linear_regression_training_distributed.h:263
daal::services::interface1::SharedPtr::reset
void reset()
Definition: daal_shared_ptr.h:265
daal::algorithms::linear_regression::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: linear_regression_training_distributed.h:182
daal::algorithms::linear_model::training::interface1::PartialResult
Provides methods to access a partial result obtained with the compute() method of the linear model-ba...
Definition: linear_model_training_types.h:135
daal::algorithms::linear_regression::training::interface1::PartialResult
Provides methods to access a partial result obtained with the compute() method of linear regression m...
Definition: linear_regression_training_types.h:218
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:162
daal::algorithms::linear_regression::training::interface1::Input
Input objects for linear regression model-based training
Definition: linear_regression_training_types.h:160
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: linear_regression_training_distributed.h:310
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:222
daal::algorithms::linear_regression::interface1::Parameter
Parameters for the linear regression algorithm.
Definition: linear_regression_model.h:82
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:81
daal::step1Local
Definition: daal_defines.h:143
daal::step2Master
Definition: daal_defines.h:144
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:125
daal::services::ErrorNullResult
Definition: error_indexes.h:122
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:76
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:86
daal::algorithms::linear_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: linear_regression_training_distributed.h:255

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