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

implicit_als_training_distributed.h
1 /* file: implicit_als_training_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2017 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 implicit ALS model-based training in the
45 // distributed processing mode
46 //--
47 */
48 
49 #ifndef __IMPLICIT_ALS_TRAINING_DISTRIBUTED_H__
50 #define __IMPLICIT_ALS_TRAINING_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "algorithms/implicit_als/implicit_als_training_types.h"
54 
55 namespace daal
56 {
57 namespace algorithms
58 {
59 namespace implicit_als
60 {
61 namespace training
62 {
63 
64 namespace interface1
65 {
76 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
77 class DAAL_EXPORT DistributedContainer
78 {};
79 
84 template<typename algorithmFPType, Method method, CpuType cpu>
85 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> : public
86  TrainingContainerIface<distributed>
87 {
88 public:
94  DistributedContainer(daal::services::Environment::env *daalEnv);
96  ~DistributedContainer();
97 
102  services::Status compute() DAAL_C11_OVERRIDE;
107  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
108 };
109 
114 template<typename algorithmFPType, Method method, CpuType cpu>
115 class DAAL_EXPORT DistributedContainer<step2Master, algorithmFPType, method, cpu> : public
116  TrainingContainerIface<distributed>
117 {
118 public:
124  DistributedContainer(daal::services::Environment::env *daalEnv);
126  ~DistributedContainer();
127 
132  services::Status compute() DAAL_C11_OVERRIDE;
137  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
138 };
139 
144 template<typename algorithmFPType, Method method, CpuType cpu>
145 class DAAL_EXPORT DistributedContainer<step3Local, algorithmFPType, method, cpu> : public
146  TrainingContainerIface<distributed>
147 {
148 public:
154  DistributedContainer(daal::services::Environment::env *daalEnv);
156  ~DistributedContainer();
157 
162  services::Status compute() DAAL_C11_OVERRIDE;
167  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
168 };
169 
174 template<typename algorithmFPType, Method method, CpuType cpu>
175 class DAAL_EXPORT DistributedContainer<step4Local, algorithmFPType, method, cpu> : public
176  TrainingContainerIface<distributed>
177 {
178 public:
184  DistributedContainer(daal::services::Environment::env *daalEnv);
186  ~DistributedContainer();
187 
192  services::Status compute() DAAL_C11_OVERRIDE;
197  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
198 };
199 
212 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = fastCSR>
213 class DAAL_EXPORT Distributed : public Training<distributed> {};
214 
230 template<typename algorithmFPType, Method method>
231 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Training<distributed>
232 {
233 public:
234  DistributedInput<step1Local> input;
235  Parameter parameter;
238  Distributed()
239  {
240  initialize();
241  }
242 
249  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
250  {
251  initialize();
252  }
253 
258  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
259 
266  services::Status setPartialResult(const DistributedPartialResultStep1Ptr& partialResult)
267  {
268  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
269  _partialResult = partialResult;
270  _pres = _partialResult.get();
271  return services::Status();
272  }
273 
280  DistributedPartialResultStep1Ptr getPartialResult() { return _partialResult; }
281 
287  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
288  {
289  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
290  }
291 
292 protected:
293  DistributedPartialResultStep1Ptr _partialResult;
294 
295  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
296  {
297  return new Distributed<step1Local, algorithmFPType, method>(*this);
298  }
299 
300  services::Status allocateResult() DAAL_C11_OVERRIDE
301  {
302  return services::Status();
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, step1Local, algorithmFPType, method)(&_env);
320  _in = &input;
321  _par = &parameter;
322  _partialResult.reset(new DistributedPartialResultStep1());
323  }
324 };
325 
341 template<typename algorithmFPType, Method method>
342 class DAAL_EXPORT Distributed<step2Master, algorithmFPType, method> : public Training<distributed>
343 {
344 public:
345  DistributedInput<step2Master> input;
346  Parameter parameter;
349  Distributed()
350  {
351  initialize();
352  }
353 
360  Distributed(const Distributed<step2Master, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
361  {
362  initialize();
363  }
364 
369  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
370 
377  services::Status setPartialResult(const DistributedPartialResultStep2Ptr& partialResult)
378  {
379  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
380  _partialResult = partialResult;
381  _pres = _partialResult.get();
382  return services::Status();
383  }
384 
391  DistributedPartialResultStep2Ptr getPartialResult() { return _partialResult; }
392 
398  services::SharedPtr<Distributed<step2Master, algorithmFPType, method> > clone() const
399  {
400  return services::SharedPtr<Distributed<step2Master, algorithmFPType, method> >(cloneImpl());
401  }
402 
403 protected:
404  DistributedPartialResultStep2Ptr _partialResult;
405 
406  virtual Distributed<step2Master, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
407  {
408  return new Distributed<step2Master, algorithmFPType, method>(*this);
409  }
410 
411  services::Status allocateResult() DAAL_C11_OVERRIDE
412  {
413  return services::Status();
414  }
415 
416  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
417  {
418  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
419  _pres = _partialResult.get();
420  return s;
421  }
422 
423  services::Status initializePartialResult() DAAL_C11_OVERRIDE
424  {
425  return services::Status();
426  }
427 
428  void initialize()
429  {
430  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Master, algorithmFPType, method)(&_env);
431  _in = &input;
432  _par = &parameter;
433  _partialResult.reset(new DistributedPartialResultStep2());
434  }
435 };
436 
437 
453 template<typename algorithmFPType, Method method>
454 class DAAL_EXPORT Distributed<step3Local, algorithmFPType, method> : public Training<distributed>
455 {
456 public:
457  DistributedInput<step3Local> input;
458  Parameter parameter;
461  Distributed()
462  {
463  initialize();
464  }
465 
472  Distributed(const Distributed<step3Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
473  {
474  initialize();
475  }
476 
481  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
482 
489  services::Status setPartialResult(const DistributedPartialResultStep3Ptr& partialResult)
490  {
491  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
492  _partialResult = partialResult;
493  _pres = _partialResult.get();
494  return services::Status();
495  }
496 
503  DistributedPartialResultStep3Ptr getPartialResult() { return _partialResult; }
504 
510  services::SharedPtr<Distributed<step3Local, algorithmFPType, method> > clone() const
511  {
512  return services::SharedPtr<Distributed<step3Local, algorithmFPType, method> >(cloneImpl());
513  }
514 
515 protected:
516  DistributedPartialResultStep3Ptr _partialResult;
517 
518  virtual Distributed<step3Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
519  {
520  return new Distributed<step3Local, algorithmFPType, method>(*this);
521  }
522 
523  services::Status allocateResult() DAAL_C11_OVERRIDE
524  {
525  return services::Status();
526  }
527 
528  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
529  {
530  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
531  _pres = _partialResult.get();
532  return s;
533  }
534 
535  services::Status initializePartialResult() DAAL_C11_OVERRIDE
536  {
537  return services::Status();
538  }
539 
540  void initialize()
541  {
542  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step3Local, algorithmFPType, method)(&_env);
543  _in = &input;
544  _par = &parameter;
545  _partialResult.reset(new DistributedPartialResultStep3());
546  }
547 };
548 
564 template<typename algorithmFPType, Method method>
565 class DAAL_EXPORT Distributed<step4Local, algorithmFPType, method> : public Training<distributed>
566 {
567 public:
568  DistributedInput<step4Local> input;
569  Parameter parameter;
572  Distributed()
573  {
574  initialize();
575  }
576 
583  Distributed(const Distributed<step4Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
584  {
585  initialize();
586  }
587 
592  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
593 
600  services::Status setPartialResult(const DistributedPartialResultStep4Ptr& partialResult)
601  {
602  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
603  _partialResult = partialResult;
604  _pres = _partialResult.get();
605  return services::Status();
606  }
607 
614  DistributedPartialResultStep4Ptr getPartialResult() { return _partialResult; }
615 
621  services::SharedPtr<Distributed<step4Local, algorithmFPType, method> > clone() const
622  {
623  return services::SharedPtr<Distributed<step4Local, algorithmFPType, method> >(cloneImpl());
624  }
625 
626 protected:
627  DistributedPartialResultStep4Ptr _partialResult;
628 
629  virtual Distributed<step4Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
630  {
631  return new Distributed<step4Local, algorithmFPType, method>(*this);
632  }
633 
634  services::Status allocateResult() DAAL_C11_OVERRIDE
635  {
636  return services::Status();
637  }
638 
639  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
640  {
641  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
642  _pres = _partialResult.get();
643  return s;
644  }
645 
646  services::Status initializePartialResult() DAAL_C11_OVERRIDE
647  {
648  return services::Status();
649  }
650 
651  void initialize()
652  {
653  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step4Local, algorithmFPType, method)(&_env);
654  _in = &input;
655  _par = &parameter;
656  _partialResult.reset(new DistributedPartialResultStep4());
657  }
658 };
660 } // namespace interface1
661 using interface1::DistributedContainer;
662 using interface1::Distributed;
663 
664 }
665 }
666 }
667 }
668 
669 #endif
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep1Ptr &partialResult)
Definition: implicit_als_training_distributed.h:266
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:322
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: implicit_als_training_distributed.h:234
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::input
DistributedInput< step4Local > input
Definition: implicit_als_training_distributed.h:568
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_distributed.h:349
daal
Definition: algorithm_base_common.h:57
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep3Ptr &partialResult)
Definition: implicit_als_training_distributed.h:489
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_distributed.h:258
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step4Local, algorithmFPType, method > &other)
Definition: implicit_als_training_distributed.h:583
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_distributed.h:572
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:418
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:522
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
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:510
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:676
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_distributed.h:461
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_distributed.h:369
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::input
DistributedInput< step3Local > input
Definition: implicit_als_training_distributed.h:457
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:77
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep4Ptr &partialResult)
Definition: implicit_als_training_distributed.h:600
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::input
DistributedInput< step2Master > input
Definition: implicit_als_training_distributed.h:345
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step3Local, algorithmFPType, method > &other)
Definition: implicit_als_training_distributed.h:472
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:398
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:132
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:231
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_distributed.h:481
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_distributed.h:238
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
Parameter parameter
Definition: implicit_als_training_distributed.h:235
daal::algorithms::implicit_als::training::interface1::Distributed
Trains the implicit ALS model in the distributed processing mode.
Definition: implicit_als_training_distributed.h:213
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep1Ptr getPartialResult()
Definition: implicit_als_training_distributed.h:280
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:565
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Master, algorithmFPType, method > &other)
Definition: implicit_als_training_distributed.h:360
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:287
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:342
daal::step4Local
Definition: daal_defines.h:145
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:621
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:454
daal::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::parameter
Parameter parameter
Definition: implicit_als_training_distributed.h:458
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::algorithms::implicit_als::training::interface1::Distributed< step3Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep3Ptr getPartialResult()
Definition: implicit_als_training_distributed.h:503
daal::step1Local
Definition: daal_defines.h:142
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep4Ptr getPartialResult()
Definition: implicit_als_training_distributed.h:614
daal::step2Master
Definition: daal_defines.h:143
daal::algorithms::implicit_als::training::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: implicit_als_training_distributed.h:249
daal::algorithms::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::parameter
Parameter parameter
Definition: implicit_als_training_distributed.h:569
daal::step3Local
Definition: daal_defines.h:144
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep2Ptr getPartialResult()
Definition: implicit_als_training_distributed.h:391
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep2Ptr &partialResult)
Definition: implicit_als_training_distributed.h:377
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:76
daal::algorithms::implicit_als::training::interface1::Distributed< step2Master, algorithmFPType, method >::parameter
Parameter parameter
Definition: implicit_als_training_distributed.h:346
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::implicit_als::training::interface1::Distributed< step4Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_distributed.h:592

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