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

implicit_als_training_distributed.h
1 /* file: implicit_als_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 implicit ALS model-based training in the
21 // distributed processing mode
22 //--
23 */
24 
25 #ifndef __IMPLICIT_ALS_TRAINING_DISTRIBUTED_H__
26 #define __IMPLICIT_ALS_TRAINING_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "algorithms/implicit_als/implicit_als_training_types.h"
30 
31 namespace daal
32 {
33 namespace algorithms
34 {
35 namespace implicit_als
36 {
37 namespace training
38 {
39 
40 namespace interface1
41 {
52 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
53 class DistributedContainer
54 {};
55 
60 template<typename algorithmFPType, Method method, CpuType cpu>
61 class DistributedContainer<step1Local, algorithmFPType, method, cpu> : public
62  TrainingContainerIface<distributed>
63 {
64 public:
70  DistributedContainer(daal::services::Environment::env *daalEnv);
72  ~DistributedContainer();
73 
78  services::Status compute() DAAL_C11_OVERRIDE;
83  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
84 };
85 
90 template<typename algorithmFPType, Method method, CpuType cpu>
91 class DistributedContainer<step2Master, algorithmFPType, method, cpu> : public
92  TrainingContainerIface<distributed>
93 {
94 public:
100  DistributedContainer(daal::services::Environment::env *daalEnv);
102  ~DistributedContainer();
103 
108  services::Status compute() DAAL_C11_OVERRIDE;
113  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
114 };
115 
120 template<typename algorithmFPType, Method method, CpuType cpu>
121 class DistributedContainer<step3Local, algorithmFPType, method, cpu> : public
122  TrainingContainerIface<distributed>
123 {
124 public:
130  DistributedContainer(daal::services::Environment::env *daalEnv);
132  ~DistributedContainer();
133 
138  services::Status compute() DAAL_C11_OVERRIDE;
143  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
144 };
145 
150 template<typename algorithmFPType, Method method, CpuType cpu>
151 class DistributedContainer<step4Local, algorithmFPType, method, cpu> : public
152  TrainingContainerIface<distributed>
153 {
154 public:
160  DistributedContainer(daal::services::Environment::env *daalEnv);
162  ~DistributedContainer();
163 
168  services::Status compute() DAAL_C11_OVERRIDE;
173  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
174 };
175 
188 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = fastCSR>
189 class DAAL_EXPORT Distributed : public Training<distributed> {};
190 
206 template<typename algorithmFPType, Method method>
207 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Training<distributed>
208 {
209 public:
210  typedef algorithms::implicit_als::training::DistributedInput<step1Local> InputType;
211  typedef algorithms::implicit_als::Parameter ParameterType;
212  typedef algorithms::implicit_als::training::Result ResultType;
213  typedef algorithms::implicit_als::training::DistributedPartialResultStep1 PartialResultType;
214 
215  DistributedInput<step1Local> input;
216  ParameterType parameter;
219  Distributed()
220  {
221  initialize();
222  }
223 
230  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
231  {
232  initialize();
233  }
234 
239  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
240 
247  services::Status setPartialResult(const DistributedPartialResultStep1Ptr& partialResult)
248  {
249  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
250  _partialResult = partialResult;
251  _pres = _partialResult.get();
252  return services::Status();
253  }
254 
261  DistributedPartialResultStep1Ptr getPartialResult() { return _partialResult; }
262 
268  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
269  {
270  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
271  }
272 
273 protected:
274  DistributedPartialResultStep1Ptr _partialResult;
275 
276  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
277  {
278  return new Distributed<step1Local, algorithmFPType, method>(*this);
279  }
280 
281  services::Status allocateResult() DAAL_C11_OVERRIDE
282  {
283  return services::Status();
284  }
285 
286  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
287  {
288  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
289  _pres = _partialResult.get();
290  return s;
291  }
292 
293  services::Status initializePartialResult() DAAL_C11_OVERRIDE
294  {
295  return services::Status();
296  }
297 
298  void initialize()
299  {
300  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
301  _in = &input;
302  _par = &parameter;
303  _partialResult.reset(new PartialResultType());
304  }
305 };
306 
322 template<typename algorithmFPType, Method method>
323 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
324 {
325 public:
326  typedef algorithms::implicit_als::training::DistributedInput<step2Master> InputType;
327  typedef algorithms::implicit_als::Parameter ParameterType;
328  typedef algorithms::implicit_als::training::Result ResultType;
329  typedef algorithms::implicit_als::training::DistributedPartialResultStep2 PartialResultType;
330 
331  DistributedInput<step2Master> input;
332  ParameterType parameter;
335  Distributed()
336  {
337  initialize();
338  }
339 
346  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
347  {
348  initialize();
349  }
350 
355  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
356 
363  services::Status setPartialResult(const DistributedPartialResultStep2Ptr& partialResult)
364  {
365  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
366  _partialResult = partialResult;
367  _pres = _partialResult.get();
368  return services::Status();
369  }
370 
377  DistributedPartialResultStep2Ptr getPartialResult() { return _partialResult; }
378 
384  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
385  {
386  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
387  }
388 
389 protected:
390  DistributedPartialResultStep2Ptr _partialResult;
391 
392  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
393  {
394  return new Distributed<step2Master, algorithmFPType, method>(*this);
395  }
396 
397  services::Status allocateResult() DAAL_C11_OVERRIDE
398  {
399  return services::Status();
400  }
401 
402  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
403  {
404  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
405  _pres = _partialResult.get();
406  return s;
407  }
408 
409  services::Status initializePartialResult() DAAL_C11_OVERRIDE
410  {
411  return services::Status();
412  }
413 
414  void initialize()
415  {
416  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
417  _in = &input;
418  _par = &parameter;
419  _partialResult.reset(new PartialResultType());
420  }
421 };
422 
423 
439 template<typename algorithmFPType, Method method>
440 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public Training<distributed>
441 {
442 public:
443  typedef algorithms::implicit_als::training::DistributedInput<step3Local> InputType;
444  typedef algorithms::implicit_als::Parameter ParameterType;
445  typedef algorithms::implicit_als::training::Result ResultType;
446  typedef algorithms::implicit_als::training::DistributedPartialResultStep3 PartialResultType;
447 
448  DistributedInput<step3Local> input;
449  ParameterType parameter;
452  Distributed()
453  {
454  initialize();
455  }
456 
463  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
464  {
465  initialize();
466  }
467 
472  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
473 
480  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialResult)
481  {
482  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
483  _partialResult = partialResult;
484  _pres = _partialResult.get();
485  return services::Status();
486  }
487 
494  DistributedPartialResultStep3Ptr getPartialResult() { return _partialResult; }
495 
501  services::SharedPtr<Distributed<step3Local, algorithmFPType, method> > clone() const
502  {
503  return services::SharedPtr<Distributed<step3Local, algorithmFPType, method> >(cloneImpl());
504  }
505 
506 protected:
507  DistributedPartialResultStep3Ptr _partialResult;
508 
509  virtual Distributed<step3Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
510  {
511  return new Distributed<step3Local, algorithmFPType, method>(*this);
512  }
513 
514  services::Status allocateResult() DAAL_C11_OVERRIDE
515  {
516  return services::Status();
517  }
518 
519  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
520  {
521  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
522  _pres = _partialResult.get();
523  return s;
524  }
525 
526  services::Status initializePartialResult() DAAL_C11_OVERRIDE
527  {
528  return services::Status();
529  }
530 
531  void initialize()
532  {
533  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
534  _in = &input;
535  _par = &parameter;
536  _partialResult.reset(new PartialResultType());
537  }
538 };
539 
555 template<typename algorithmFPType, Method method>
556 class DAAL_EXPORT Distributed<step4Local, algorithmFPType, method> : public Training<distributed>
557 {
558 public:
559  typedef algorithms::implicit_als::training::DistributedInput<step4Local> InputType;
560  typedef algorithms::implicit_als::Parameter ParameterType;
561  typedef algorithms::implicit_als::training::Result ResultType;
562  typedef algorithms::implicit_als::training::DistributedPartialResultStep4 PartialResultType;
563 
564  DistributedInput<step4Local> input;
565  ParameterType parameter;
568  Distributed()
569  {
570  initialize();
571  }
572 
579  Distributed(const Distributed<step4Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
580  {
581  initialize();
582  }
583 
588  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
589 
596  services::Status setPartialResult(const DistributedPartialResultStep4Ptr& partialResult)
597  {
598  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
599  _partialResult = partialResult;
600  _pres = _partialResult.get();
601  return services::Status();
602  }
603 
610  DistributedPartialResultStep4Ptr getPartialResult() { return _partialResult; }
611 
617  services::SharedPtr<Distributed<step4Local, algorithmFPType, method> > clone() const
618  {
619  return services::SharedPtr<Distributed<step4Local, algorithmFPType, method> >(cloneImpl());
620  }
621 
622 protected:
623  DistributedPartialResultStep4Ptr _partialResult;
624 
625  virtual Distributed<step4Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
626  {
627  return new Distributed<step4Local, algorithmFPType, method>(*this);
628  }
629 
630  services::Status allocateResult() DAAL_C11_OVERRIDE
631  {
632  return services::Status();
633  }
634 
635  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
636  {
637  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
638  _pres = _partialResult.get();
639  return s;
640  }
641 
642  services::Status initializePartialResult() DAAL_C11_OVERRIDE
643  {
644  return services::Status();
645  }
646 
647  void initialize()
648  {
649  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step4Local, algorithmFPType, method)(&_env);
650  _in = &input;
651  _par = &parameter;
652  _partialResult.reset(new PartialResultType());
653  }
654 };
656 } // namespace interface1
657 using interface1::DistributedContainer;
658 using interface1::Distributed;
659 
660 }
661 }
662 }
663 }
664 
665 #endif
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep4Ptr &partialResult)
Definition: implicit_als_training_distributed.h:596
daal::algorithms::implicit_als::training::interface1::Distributed
Trains the implicit ALS model in the distributed processing mode.
Definition: implicit_als_training_distributed.h:189
daal::algorithms::implicit_als::training::interface1::DistributedInput< step3Local >
Input objects for the implicit ALS training algorithm in the third step of the distributed processing...
Definition: implicit_als_training_types.h:498
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: implicit_als_training_distributed.h:230
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >
Trains the implicit ALS model in the second step of the distributed processing mode.
Definition: implicit_als_training_distributed.h:323
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_training_distributed.h:565
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: implicit_als_training_distributed.h:268
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step3Local, algorithmFPType, method > > clone() const
Definition: implicit_als_training_distributed.h:501
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step4Local, algorithmFPType, method > &other)
Definition: implicit_als_training_distributed.h:579
daal::step2Master
Definition: daal_defines.h:124
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep2Ptr getPartialResult()
Definition: implicit_als_training_distributed.h:377
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::input
DistributedInput< step4Local > input
Definition: implicit_als_training_distributed.h:564
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialResult)
Definition: implicit_als_training_distributed.h:480
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::input
DistributedInput< step3Local > input
Definition: implicit_als_training_distributed.h:448
daal::algorithms::implicit_als::training::interface1::DistributedInput< step2Master >
Input objects for the implicit ALS training algorithm in the second step of the distributed processin...
Definition: implicit_als_training_types.h:394
daal::step3Local
Definition: daal_defines.h:125
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_distributed.h:239
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: implicit_als_training_distributed.h:331
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step4Local, algorithmFPType, method > > clone() const
Definition: implicit_als_training_distributed.h:617
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::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep1Ptr &partialResult)
Definition: implicit_als_training_distributed.h:247
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_distributed.h:568
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >
Trains the implicit ALS model in the first step of the distributed processing mode.
Definition: implicit_als_training_distributed.h:207
daal::algorithms::implicit_als::training::interface1::DistributedContainer
Class containing methods to compute the result of implicit ALS model-based training in the distribute...
Definition: implicit_als_training_distributed.h:53
daal::step4Local
Definition: daal_defines.h:126
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_distributed.h:472
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >
Trains the implicit ALS model in the fourth step of the distributed processing mode.
Definition: implicit_als_training_distributed.h:556
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: implicit_als_training_distributed.h:215
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_distributed.h:355
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_distributed.h:452
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_training_distributed.h:332
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::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: implicit_als_training_distributed.h:463
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_training_distributed.h:449
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep4Ptr getPartialResult()
Definition: implicit_als_training_distributed.h:610
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_distributed.h:335
daal::algorithms::implicit_als::training::interface1::DistributedInput< step1Local >
Input objects for the implicit ALS training algorithm in the first step of the distributed processing...
Definition: implicit_als_training_types.h:298
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_training_distributed.h:216
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >
Trains the implicit ALS model in the third step of the distributed processing mode.
Definition: implicit_als_training_distributed.h:440
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep2Ptr &partialResult)
Definition: implicit_als_training_distributed.h:363
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: implicit_als_training_distributed.h:494
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: implicit_als_training_distributed.h:346
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep1Ptr getPartialResult()
Definition: implicit_als_training_distributed.h:261
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_distributed.h:219
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52
daal::algorithms::implicit_als::training::interface1::DistributedInput< step4Local >
Input objects for the implicit ALS training algorithm in the fourth step of the distributed processin...
Definition: implicit_als_training_types.h:652
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Master, algorithmFPType, method > > clone() const
Definition: implicit_als_training_distributed.h:384
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_distributed.h:588

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