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

implicit_als_training_init_distributed.h
1 /* file: implicit_als_training_init_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 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  typedef algorithms::implicit_als::training::init::DistributedInput<step1Local> InputType;
171  typedef algorithms::implicit_als::training::init::DistributedParameter ParameterType;
172  typedef algorithms::implicit_als::training::init::Result ResultType;
173  typedef algorithms::implicit_als::training::init::PartialResult PartialResultType;
174 
175  DistributedInput<step1Local> input;
176  ParameterType parameter;
179  Distributed()
180  {
181  initialize();
182  }
183 
190  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
191  {
192  initialize();
193  }
194 
199  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
200 
205  services::Status setPartialResult(const PartialResultPtr& partialResult)
206  {
207  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
208  _partialResult = partialResult;
209  _pres = _partialResult.get();
210  return services::Status();
211  }
212 
217  PartialResultPtr getPartialResult() { return _partialResult; }
218 
224  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
225  {
226  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
227  }
228 
229 protected:
230  PartialResultPtr _partialResult;
231 
232  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
233  {
234  return new Distributed<step1Local, algorithmFPType, method>(*this);
235  }
236 
237  services::Status allocateResult() DAAL_C11_OVERRIDE
238  {
239  return services::Status();
240  }
241 
242  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
243  {
244  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, method);
245  _pres = _partialResult.get();
246  return s;
247  }
248 
249  services::Status initializePartialResult() DAAL_C11_OVERRIDE
250  {
251  return services::Status();
252  }
253 
254  void initialize()
255  {
256  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
257  _in = &input;
258  _par = &parameter;
259  _partialResult.reset(new PartialResultType());
260  }
261 };
262 
274 template<typename algorithmFPType, Method method>
275 class DAAL_EXPORT Distributed<step2Local, algorithmFPType, method> : public Training<distributed>
276 {
277 public:
278  typedef algorithms::implicit_als::training::init::DistributedInput<step2Local> InputType;
279  typedef algorithms::implicit_als::training::init::Result ResultType;
280  typedef algorithms::implicit_als::training::init::DistributedPartialResultStep2 PartialResultType;
281 
282  DistributedInput<step2Local> input;
285  Distributed()
286  {
287  initialize();
288  }
289 
296  Distributed(const Distributed<step2Local, algorithmFPType, method> &other)
297  {
298  initialize();
299  input.set(inputOfStep2FromStep1, other.input.get(inputOfStep2FromStep1));
300  }
301 
306  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
307 
312  services::Status setPartialResult(const DistributedPartialResultStep2Ptr& partialResult)
313  {
314  DAAL_CHECK(partialResult, services::ErrorNullPartialResult);
315  _partialResult = partialResult;
316  _pres = _partialResult.get();
317  return services::Status();
318  }
319 
324  DistributedPartialResultStep2Ptr getPartialResult() { return _partialResult; }
325 
331  services::SharedPtr<Distributed<step2Local, algorithmFPType, method> > clone() const
332  {
333  return services::SharedPtr<Distributed<step2Local, algorithmFPType, method> >(cloneImpl());
334  }
335 
336 protected:
337  DistributedPartialResultStep2Ptr _partialResult;
338 
339  virtual Distributed<step2Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
340  {
341  return new Distributed<step2Local, algorithmFPType, method>(*this);
342  }
343 
344  services::Status allocateResult() DAAL_C11_OVERRIDE
345  {
346  return services::Status();
347  }
348 
349  services::Status allocatePartialResult() DAAL_C11_OVERRIDE
350  {
351  services::Status s = _partialResult->allocate<algorithmFPType>(&input, NULL, method);
352  _pres = _partialResult.get();
353  return s;
354  }
355 
356  services::Status initializePartialResult() DAAL_C11_OVERRIDE
357  {
358  return services::Status();
359  }
360 
361  void initialize()
362  {
363  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step2Local, algorithmFPType, method)(&_env);
364  _in = &input;
365  _par = NULL;
366  _partialResult.reset(new PartialResultType());
367  }
368 };
370 } // namespace interface1
371 using interface1::DistributedContainer;
372 using interface1::Distributed;
373 
374 }
375 }
376 }
377 }
378 }
379 
380 #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:217
daal::algorithms::implicit_als::training::init::interface1::DistributedInput
Input objects for the implicit ALS initialization algorithm in the distributed processing mode ...
Definition: implicit_als_training_init_types.h:269
daal::step2Local
Definition: daal_defines.h:148
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:275
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:306
daal::services::interface1::Environment::_envStruct
The environment structure.
Definition: env_detect.h:95
daal::services::interface1::Status
Class that holds the results of API calls. In case of API routine failure it contains the list of err...
Definition: error_handling.h:491
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:199
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::input
DistributedInput< step2Local > input
Definition: implicit_als_training_init_distributed.h:282
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:190
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:205
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::implicit_als::training::init::interface1::DistributedPartialResultStep2
Provides methods to access partial results obtained with the compute() method of the implicit ALS ini...
Definition: implicit_als_training_init_types.h:475
daal::algorithms::implicit_als::training::init::interface1::PartialResult
Provides methods to access partial results obtained with the compute() method of the implicit ALS ini...
Definition: implicit_als_training_init_types.h:398
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:312
daal::algorithms::implicit_als::training::init::interface1::DistributedInput< step2Local >::set
void set(Step2LocalInputId id, const data_management::KeyValueDataCollectionPtr &ptr)
daal::algorithms::implicit_als::training::init::interface1::DistributedInput< step2Local >::get
data_management::KeyValueDataCollectionPtr get(Step2LocalInputId id) const
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:324
daal::distributed
Definition: daal_defines.h:133
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::services::interface1::SharedPtr
Shared pointer that retains shared ownership of an object through a pointer. Several SharedPtr object...
Definition: daal_shared_ptr.h:187
daal::services::interface1::SharedPtr::get
T * get() const
Definition: daal_shared_ptr.h:332
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::services::interface1::SharedPtr::reset
void reset()
Definition: daal_shared_ptr.h:265
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:331
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:296
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_init_distributed.h:179
daal::algorithms::implicit_als::training::init::inputOfStep2FromStep1
Definition: implicit_als_training_init_types.h:103
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::Result
Provides methods to access the results obtained with the compute() method of the implicit ALS initial...
Definition: implicit_als_training_init_types.h:530
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:143
daal::algorithms::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: implicit_als_training_init_distributed.h:175
daal::algorithms::implicit_als::training::init::interface1::Distributed< step2Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_training_init_distributed.h:285
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::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: implicit_als_training_init_distributed.h:224
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::implicit_als::training::init::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_training_init_distributed.h:176
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.