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

implicit_als_training_init_distributed.h
1 /* file: implicit_als_training_init_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 the implicit ALS initialization algorithm
45 // in the distributed processing mode
46 //--
47 */
48 
49 #ifndef __IMPLICIT_ALS_TRAINING_INIT_DISTRIBUTED_H__
50 #define __IMPLICIT_ALS_TRAINING_INIT_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "algorithms/implicit_als/implicit_als_training_init_types.h"
54 
55 namespace daal
56 {
57 namespace algorithms
58 {
59 namespace implicit_als
60 {
61 namespace training
62 {
63 namespace init
64 {
65 
66 namespace interface1
67 {
78 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
79 class DAAL_EXPORT DistributedContainer {};
80 
85 template<typename algorithmFPType, Method method, CpuType cpu>
86 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> : public
87  TrainingContainerIface<distributed>
88 {
89 public:
95  DistributedContainer(daal::services::Environment::env *daalEnv);
97  ~DistributedContainer();
102  services::Status compute() DAAL_C11_OVERRIDE;
107  services::Status finalizeCompute() DAAL_C11_OVERRIDE { return services::Status(); }
108 };
109 
114 template<typename algorithmFPType, Method method, CpuType cpu>
115 class DAAL_EXPORT DistributedContainer<step2Local, algorithmFPType, method, cpu> : public
116  TrainingContainerIface<distributed>
117 {
118 public:
124  DistributedContainer(daal::services::Environment::env *daalEnv);
126  ~DistributedContainer();
131  services::Status compute() DAAL_C11_OVERRIDE;
136  services::Status finalizeCompute() DAAL_C11_OVERRIDE { return services::Status(); }
137 };
138 
139 
152 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = fastCSR>
153 class DAAL_EXPORT Distributed {};
154 
166 template<typename algorithmFPType, Method method>
167 class DAAL_EXPORT Distributed<step1Local, algorithmFPType, method> : public Training<distributed>
168 {
169 public:
170  DistributedInput<step1Local> input;
171  DistributedParameter parameter;
174  Distributed()
175  {
176  initialize();
177  }
178 
185  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
186  {
187  initialize();
188  }
189 
194  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
195 
200  services::Status setPartialResult(const PartialResultPtr& partialResult)
201  {
202  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
203  _partialResult = partialResult;
204  _pres = _partialResult.get();
205  return services::Status();
206  }
207 
212  PartialResultPtr getPartialResult() { return _partialResult; }
213 
219  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
220  {
221  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
222  }
223 
224 protected:
225  PartialResultPtr _partialResult;
226 
227  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
228  {
229  return new Distributed<step1Local, algorithmFPType, method>(*this);
230  }
231 
232  services::Status allocateResult() DAAL_C11_OVERRIDE
233  {
234  return services::Status();
235  }
236 
237  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
238  {
239  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
240  _pres = _partialResult.get();
241  return s;
242  }
243 
244  services::Status initializePartialResult() DAAL_C11_OVERRIDE
245  {
246  return services::Status();
247  }
248 
249  void initialize()
250  {
251  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
252  _in = &input;
253  _par = &parameter;
254  _partialResult.reset(new PartialResult());
255  }
256 };
257 
269 template<typename algorithmFPType, Method method>
270 class DAAL_EXPORT Distributed<step2Local, algorithmFPType, method> : public Training<distributed>
271 {
272 public:
273  DistributedInput<step2Local> input;
276  Distributed()
277  {
278  initialize();
279  }
280 
287  Distributed(const Distributed<step2Local, algorithmFPType, method> &other)
288  {
289  initialize();
290  input.set(inputOfStep2FromStep1, other.input.get(inputOfStep2FromStep1));
291  }
292 
297  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
298 
303  services::Status setPartialResult(const DistributedPartialResultStep2Ptr& partialResult)
304  {
305  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
306  _partialResult = partialResult;
307  _pres = _partialResult.get();
308  return services::Status();
309  }
310 
315  DistributedPartialResultStep2Ptr getPartialResult() { return _partialResult; }
316 
322  services::SharedPtr<Distributed<step2Local, algorithmFPType, method> > clone() const
323  {
324  return services::SharedPtr<Distributed<step2Local, algorithmFPType, method> >(cloneImpl());
325  }
326 
327 protected:
328  DistributedPartialResultStep2Ptr _partialResult;
329 
330  virtual Distributed<step2Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
331  {
332  return new Distributed<step2Local, algorithmFPType, method>(*this);
333  }
334 
335  services::Status allocateResult() DAAL_C11_OVERRIDE
336  {
337  return services::Status();
338  }
339 
340  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
341  {
342  services::Status s = _partialResult->allocate<algorithmFPType>(&input, NULL, method);
343  _pres = _partialResult.get();
344  return s;
345  }
346 
347  services::Status initializePartialResult() DAAL_C11_OVERRIDE
348  {
349  return services::Status();
350  }
351 
352  void initialize()
353  {
354  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Local, algorithmFPType, method)(&_env);
355  _in = &input;
356  _par = NULL;
357  _partialResult.reset(new DistributedPartialResultStep2());
358  }
359 };
361 } // namespace interface1
362 using interface1::DistributedContainer;
363 using interface1::Distributed;
364 
365 }
366 }
367 }
368 }
369 }
370 
371 #endif
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:136
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: implicit_als_training_init_distributed.h:212
daal::algorithms::implicit_als::training::init::inputOfStep2FromStep1
Definition: implicit_als_training_init_types.h:103
daal::step2Local
Definition: daal_defines.h:147
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:270
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:297
daal
Definition: algorithm_base_common.h:57
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:194
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::input
DistributedInput< step2Local > input
Definition: implicit_als_training_init_distributed.h:273
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: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:185
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:200
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
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:219
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:303
daal::algorithms::implicit_als::training::init::interface1::DistributedInput< step2Local >::set
void set(Step2LocalInputId id, const data_management::KeyValueDataCollectionPtr &ptr)
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::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::getPartialResult
DistributedPartialResultStep2Ptr getPartialResult()
Definition: implicit_als_training_init_distributed.h:315
daal::distributed
Definition: daal_defines.h:132
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:167
daal::algorithms::implicit_als::training::init::interface1::DistributedParameter
Parameters of the compute() method of the implicit ALS initialization algorithm in the distributed co...
Definition: implicit_als_training_init_types.h:204
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:287
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_init_distributed.h:174
daal::algorithms::implicit_als::training::init::interface1::DistributedInput< step2Local >::get
data_management::KeyValueDataCollectionPtr get(Step2LocalInputId id) const
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:107
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:322
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:142
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
DistributedParameter parameter
Definition: implicit_als_training_init_distributed.h:171
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: implicit_als_training_init_distributed.h:170
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_init_distributed.h:276
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:299
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:278
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::init::interface1::Distributed
Initializes the implicit ALS model in the distributed processing mode.
Definition: implicit_als_training_init_distributed.h:153
daal::algorithms::Training
Provides methods to train models that depend on the data provided. For example, these methods enable ...
Definition: training.h:86

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