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

ridge_regression_training_distributed.h
1 /* file: ridge_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 ridge regression model-based training in the distributed processing mode
21 //--
22 */
23 
24 #ifndef __RIDGE_REGRESSION_TRAINING_DISTRIBUTED_H__
25 #define __RIDGE_REGRESSION_TRAINING_DISTRIBUTED_H__
26 
27 #include "algorithms/algorithm.h"
28 #include "data_management/data/numeric_table.h"
29 #include "services/daal_defines.h"
30 #include "services/daal_memory.h"
31 #include "algorithms/ridge_regression/ridge_regression_training_types.h"
32 #include "algorithms/ridge_regression/ridge_regression_training_online.h"
33 #include "algorithms/ridge_regression/ridge_regression_model.h"
34 
35 namespace daal
36 {
37 namespace algorithms
38 {
39 namespace ridge_regression
40 {
41 namespace training
42 {
43 namespace interface1
44 {
54 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
55 class DistributedContainer
56 {};
57 
62 template<typename algorithmFPType, Method method, CpuType cpu>
63 class DistributedContainer<step2Master, algorithmFPType, method, cpu> : public TrainingContainerIface<distributed>
64 {
65 public:
70  DistributedContainer(daal::services::Environment::env *daalEnv);
71 
73  ~DistributedContainer();
74 
80  services::Status compute() DAAL_C11_OVERRIDE;
81 
87  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
88 };
89 
108 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = normEqDense>
109 class DAAL_EXPORT Distributed : public Training<distributed> {};
110 
128 template<typename algorithmFPType, Method method>
129 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Online<algorithmFPType, method>
130 {
131 public:
132  typedef Online<algorithmFPType, method> super;
133 
134  typedef typename super::InputType InputType;
135  typedef typename super::ParameterType ParameterType;
136  typedef typename super::ResultType ResultType;
137  typedef typename super::PartialResultType PartialResultType;
138 
140  Distributed<step1Local, algorithmFPType, method>() : Online<algorithmFPType, method>()
141  {}
142 
148  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : Online<algorithmFPType, method>(other)
149  {}
150 
151  ~Distributed() {}
152 
158  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
159  {
160  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
161  }
162 
163 protected:
164  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
165  {
166  return new Distributed<step1Local, algorithmFPType, method>(*this);
167  }
168 
169 }; // class : public Training
170 
187 template<typename algorithmFPType, Method method>
188 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
189 {
190 public:
191  typedef algorithms::ridge_regression::training::DistributedInput<step2Master> InputType;
192  typedef algorithms::ridge_regression::TrainParameter ParameterType;
193  typedef algorithms::ridge_regression::training::Result ResultType;
194  typedef algorithms::ridge_regression::training::PartialResult PartialResultType;
195 
197  Distributed()
198  {
199  initialize();
200  }
201 
207  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
208  {
209  initialize();
210  }
211 
212  ~Distributed() {}
213 
218  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
219 
226  services::Status setPartialResult(const PartialResultPtr& partialResult)
227  {
228  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
229  _partialResult = partialResult;
230  _pres = _partialResult.get();
231  return services::Status();
232  }
233 
238  PartialResultPtr getPartialResult() { return _partialResult; }
239 
246  services::Status setResult(const ResultPtr& res)
247  {
248  DAAL_CHECK(res, services::ErrorNullResult)
249  _result = res;
250  _res = _result.get();
251  return services::Status();
252  }
253 
258  ResultPtr getResult() { return _result; }
259 
265  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
266  {
267  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
268  }
269 
270  DistributedInput<step2Master> input;
271  ParameterType parameter;
273 protected:
274  PartialResultPtr _partialResult;
275  ResultPtr _result;
276 
277  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
278  {
279  return new Distributed<step2Master, algorithmFPType, method>(*this);
280  }
281 
282  services::Status allocateResult() DAAL_C11_OVERRIDE
283  {
284  services::Status s = _result->allocate<algorithmFPType>(_pres, &parameter, method);
285  _res = _result.get();
286  return s;
287  }
288 
289  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
290  {
291  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
292  _pres = _partialResult.get();
293  return s;
294  }
295 
296  services::Status initializePartialResult() DAAL_C11_OVERRIDE
297  {
298  return services::Status();
299  }
300 
301  void initialize()
302  {
303  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
304  _in = &input;
305  _par = &parameter;
306  _partialResult.reset(new PartialResultType());
307  _result.reset(new ResultType());
308  }
309 
310 }; // class : public Training
312 } // namespace interface1
313 
314 using interface1::DistributedContainer;
315 using interface1::Distributed;
316 
317 } // namespace training
318 } // namespace ridge_regression
319 } // namespace algorithms
320 } // namespace daal
321 
322 #endif
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: ridge_regression_training_distributed.h:265
daal::algorithms::ridge_regression::training::interface1::Online
Provides methods for ridge regression model-based training in the online processing mode...
Definition: ridge_regression_training_online.h:97
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: ridge_regression_training_distributed.h:258
daal::algorithms::ridge_regression::training::interface1::Distributed< step1Local, algorithmFPType, method >
Performs ridge regression model-based training in the the first step of the distributed processing mo...
Definition: ridge_regression_training_distributed.h:129
daal::algorithms::ridge_regression::training::interface1::DistributedContainer
Class containing methods for ridge regression model-based training in the distributed processing mode...
Definition: ridge_regression_training_distributed.h:55
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >
Performs ridge regression model-based training in the the second step of distributed processing mode...
Definition: ridge_regression_training_distributed.h:188
daal::step2Master
Definition: daal_defines.h:124
daal::services::ErrorNullResult
Definition: error_indexes.h:98
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_defines.h
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: ridge_regression_training_distributed.h:270
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: ridge_regression_training_distributed.h:271
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: ridge_regression_training_distributed.h:197
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::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: ridge_regression_training_distributed.h:218
daal::algorithms::ridge_regression::training::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: ridge_regression_training_distributed.h:158
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: ridge_regression_training_distributed.h:238
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &res)
Definition: ridge_regression_training_distributed.h:246
daal::algorithms::ridge_regression::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: ridge_regression_training_distributed.h:148
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: ridge_regression_training_distributed.h:207
daal::algorithms::ridge_regression::training::interface1::DistributedInput< step2Master >
Input object for ridge regression model-based training in the second step of the distributed processi...
Definition: ridge_regression_training_types.h:280
daal::algorithms::ridge_regression::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: ridge_regression_training_distributed.h:226
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52
daal::algorithms::ridge_regression::training::interface1::Distributed
Provides methods for ridge regression model-based training in the distributed processing mode...
Definition: ridge_regression_training_distributed.h:109

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