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

implicit_als_training_init_distributed.h
1 /* file: implicit_als_training_init_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 the implicit ALS initialization algorithm
21 // in the distributed processing mode
22 //--
23 */
24 
25 #ifndef __IMPLICIT_ALS_TRAINING_INIT_DISTRIBUTED_H__
26 #define __IMPLICIT_ALS_TRAINING_INIT_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "algorithms/implicit_als/implicit_als_training_init_types.h"
30 
31 namespace daal
32 {
33 namespace algorithms
34 {
35 namespace implicit_als
36 {
37 namespace training
38 {
39 namespace init
40 {
41 
42 namespace interface1
43 {
54 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
55 class DistributedContainer {};
56 
61 template<typename algorithmFPType, Method method, CpuType cpu>
62 class DistributedContainer<step1Local, algorithmFPType, method, cpu> : public
63  TrainingContainerIface<distributed>
64 {
65 public:
71  DistributedContainer(daal::services::Environment::env *daalEnv);
73  ~DistributedContainer();
78  services::Status compute() DAAL_C11_OVERRIDE;
83  services::Status finalizeCompute() DAAL_C11_OVERRIDE { return services::Status(); }
84 };
85 
90 template<typename algorithmFPType, Method method, CpuType cpu>
91 class DistributedContainer<step2Local, algorithmFPType, method, cpu> : public
92  TrainingContainerIface<distributed>
93 {
94 public:
100  DistributedContainer(daal::services::Environment::env *daalEnv);
102  ~DistributedContainer();
107  services::Status compute() DAAL_C11_OVERRIDE;
112  services::Status finalizeCompute() DAAL_C11_OVERRIDE { return services::Status(); }
113 };
114 
115 
128 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = fastCSR>
129 class DAAL_EXPORT Distributed {};
130 
142 template<typename algorithmFPType, Method method>
143 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Training<distributed>
144 {
145 public:
146  typedef algorithms::implicit_als::training::init::DistributedInput<step1Local> InputType;
147  typedef algorithms::implicit_als::training::init::DistributedParameter ParameterType;
148  typedef algorithms::implicit_als::training::init::Result ResultType;
149  typedef algorithms::implicit_als::training::init::PartialResult PartialResultType;
150 
151  DistributedInput<step1Local> input;
152  ParameterType parameter;
155  Distributed()
156  {
157  initialize();
158  }
159 
166  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
167  {
168  initialize();
169  }
170 
175  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
176 
181  services::Status setPartialResult(const PartialResultPtr& partialResult)
182  {
183  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
184  _partialResult = partialResult;
185  _pres = _partialResult.get();
186  return services::Status();
187  }
188 
193  PartialResultPtr getPartialResult() { return _partialResult; }
194 
200  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
201  {
202  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
203  }
204 
205 protected:
206  PartialResultPtr _partialResult;
207 
208  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
209  {
210  return new Distributed<step1Local, algorithmFPType, method>(*this);
211  }
212 
213  services::Status allocateResult() DAAL_C11_OVERRIDE
214  {
215  return services::Status();
216  }
217 
218  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
219  {
220  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
221  _pres = _partialResult.get();
222  return s;
223  }
224 
225  services::Status initializePartialResult() DAAL_C11_OVERRIDE
226  {
227  return services::Status();
228  }
229 
230  void initialize()
231  {
232  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
233  _in = &input;
234  _par = &parameter;
235  _partialResult.reset(new PartialResultType());
236  }
237 };
238 
250 template<typename algorithmFPType, Method method>
251 class DAAL_EXPORT Distributed<step2Local, algorithmFPType, method> : public Training<distributed>
252 {
253 public:
254  typedef algorithms::implicit_als::training::init::DistributedInput<step2Local> InputType;
255  typedef algorithms::implicit_als::training::init::Result ResultType;
256  typedef algorithms::implicit_als::training::init::DistributedPartialResultStep2 PartialResultType;
257 
258  DistributedInput<step2Local> input;
261  Distributed()
262  {
263  initialize();
264  }
265 
272  Distributed(const Distributed<step2Local, algorithmFPType, method> &other)
273  {
274  initialize();
275  input.set(inputOfStep2FromStep1, other.input.get(inputOfStep2FromStep1));
276  }
277 
282  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
283 
288  services::Status setPartialResult(const DistributedPartialResultStep2Ptr& partialResult)
289  {
290  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
291  _partialResult = partialResult;
292  _pres = _partialResult.get();
293  return services::Status();
294  }
295 
300  DistributedPartialResultStep2Ptr getPartialResult() { return _partialResult; }
301 
307  services::SharedPtr<Distributed<step2Local, algorithmFPType, method> > clone() const
308  {
309  return services::SharedPtr<Distributed<step2Local, algorithmFPType, method> >(cloneImpl());
310  }
311 
312 protected:
313  DistributedPartialResultStep2Ptr _partialResult;
314 
315  virtual Distributed<step2Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
316  {
317  return new Distributed<step2Local, algorithmFPType, method>(*this);
318  }
319 
320  services::Status allocateResult() DAAL_C11_OVERRIDE
321  {
322  return services::Status();
323  }
324 
325  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
326  {
327  services::Status s = _partialResult->allocate<algorithmFPType>(&input, NULL, method);
328  _pres = _partialResult.get();
329  return s;
330  }
331 
332  services::Status initializePartialResult() DAAL_C11_OVERRIDE
333  {
334  return services::Status();
335  }
336 
337  void initialize()
338  {
339  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Local, algorithmFPType, method)(&_env);
340  _in = &input;
341  _par = NULL;
342  _partialResult.reset(new PartialResultType());
343  }
344 };
346 } // namespace interface1
347 using interface1::DistributedContainer;
348 using interface1::Distributed;
349 
350 }
351 }
352 }
353 }
354 }
355 
356 #endif
daal::step1Local
Definition: daal_defines.h:123
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const DistributedPartialResultStep2Ptr &partialResult)
Definition: implicit_als_training_init_distributed.h:288
daal::algorithms::implicit_als::training::init::inputOfStep2FromStep1
Definition: implicit_als_training_init_types.h:79
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: implicit_als_training_init_distributed.h:166
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_init_distributed.h:261
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult)
Definition: implicit_als_training_init_distributed.h:181
daal::algorithms::implicit_als::training::init::interface1::DistributedInput< step2Local >
Input objects for the implicit ALS initialization algorithm in the second step of the distributed pro...
Definition: implicit_als_training_init_types.h:275
daal::algorithms::implicit_als::training::init::interface1::DistributedInput< step2Local >::get
data_management::KeyValueDataCollectionPtr get(Step2LocalInputId id) const
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_init_distributed.h:282
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_init_distributed.h:155
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_training_init_distributed.h:175
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::input
DistributedInput< step2Local > input
Definition: implicit_als_training_init_distributed.h:258
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: implicit_als_training_init_distributed.h:193
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >
Initializes the implicit ALS model in the second step of the distributed processing mode...
Definition: implicit_als_training_init_distributed.h:251
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: implicit_als_training_init_distributed.h:151
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::init::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: implicit_als_training_init_distributed.h:200
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::init::interface1::DistributedContainer< step2Local, algorithmFPType, method, cpu >::finalizeCompute
services::Status finalizeCompute() DAAL_C11_OVERRIDE
Definition: implicit_als_training_init_distributed.h:112
daal::algorithms::implicit_als::training::init::interface1::Distributed
Initializes the implicit ALS model in the distributed processing mode.
Definition: implicit_als_training_init_distributed.h:129
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >
Initializes the implicit ALS model in the first step of the distributed processing mode...
Definition: implicit_als_training_init_distributed.h:143
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep2Ptr getPartialResult()
Definition: implicit_als_training_init_distributed.h:300
daal::algorithms::implicit_als::training::init::interface1::DistributedInput< step1Local >
Input objects for the implicit ALS initialization algorithm in the first step of the distributed proc...
Definition: implicit_als_training_init_types.h:254
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_training_init_distributed.h:152
daal::algorithms::implicit_als::training::init::interface1::DistributedContainer
Class containing methods to compute the results of the implicit ALS initialization algorithm in the d...
Definition: implicit_als_training_init_distributed.h:55
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:107
daal::distributed
Definition: daal_defines.h:113
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step2Local, algorithmFPType, method > > clone() const
Definition: implicit_als_training_init_distributed.h:307
daal::algorithms::TrainingContainerIface
Abstract interface class that provides virtual methods to access and run implementations of the model...
Definition: training.h:52
daal::step2Local
Definition: daal_defines.h:128
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step2Local, algorithmFPType, method > &other)
Definition: implicit_als_training_init_distributed.h:272
daal::algorithms::implicit_als::training::init::interface1::DistributedContainer< step1Local, algorithmFPType, method, cpu >::finalizeCompute
services::Status finalizeCompute() DAAL_C11_OVERRIDE
Definition: implicit_als_training_init_distributed.h:83

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