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

implicit_als_predict_ratings_distributed.h
1 /* file: implicit_als_predict_ratings_distributed.h */
2 /*******************************************************************************
3 * Copyright 2014-2018 Intel Corporation.
4 *
5 * This software and the related documents are Intel copyrighted materials, and
6 * your use of them is governed by the express license under which they were
7 * provided to you (License). Unless the License provides otherwise, you may not
8 * use, modify, copy, publish, distribute, disclose or transmit this software or
9 * the related documents without Intel's prior written permission.
10 *
11 * This software and the related documents are provided as is, with no express
12 * or implied warranties, other than those that are expressly stated in the
13 * License.
14 *******************************************************************************/
15 
16 /*
17 //++
18 // Implementation of the interface for implicit ALS model-based ratings prediction
19 // in the distributed processing mode
20 //--
21 */
22 
23 #ifndef __IMPLICIT_ALS_PREDICT_RATINGS_DISTRIBUTED_H__
24 #define __IMPLICIT_ALS_PREDICT_RATINGS_DISTRIBUTED_H__
25 
26 #include "algorithms/algorithm.h"
27 #include "algorithms/implicit_als/implicit_als_predict_ratings_types.h"
28 
29 namespace daal
30 {
31 namespace algorithms
32 {
33 namespace implicit_als
34 {
35 namespace prediction
36 {
37 namespace ratings
38 {
39 
40 namespace interface1
41 {
51 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
52 class DAAL_EXPORT DistributedContainer
53 {};
54 
60 template<typename algorithmFPType, Method method, CpuType cpu>
61 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> : public DistributedPredictionContainerIface
62 {
63 public:
69  DistributedContainer(daal::services::Environment::env *daalEnv);
70  ~DistributedContainer();
71 
76  services::Status compute() DAAL_C11_OVERRIDE;
81  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
82 };
83 
101 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
102 class Distributed : public daal::algorithms::DistributedPrediction {};
103 
118 template<typename algorithmFPType, Method method>
119 class Distributed<step1Local, algorithmFPType, method> : public daal::algorithms::DistributedPrediction
120 {
121 public:
122  typedef algorithms::implicit_als::prediction::ratings::DistributedInput<step1Local> InputType;
123  typedef algorithms::implicit_als::Parameter ParameterType;
124  typedef algorithms::implicit_als::prediction::ratings::Result ResultType;
125  typedef algorithms::implicit_als::prediction::ratings::PartialResult PartialResultType;
126 
127  DistributedInput<step1Local> input;
128  ParameterType parameter;
133  Distributed()
134  {
135  initialize();
136  }
137 
144  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
145  {
146  initialize();
147  }
148 
149  virtual ~Distributed() {}
150 
155  ResultPtr getResult()
156  {
157  return _partialResult->get(finalResult);
158  }
159 
164  PartialResultPtr getPartialResult()
165  {
166  return _partialResult;
167  }
168 
173  services::Status setResult(const ResultPtr &result)
174  {
175  DAAL_CHECK(result, services::ErrorNullResult)
176  _partialResult->set(finalResult, result);
177  _pres = _partialResult.get();
178  return services::Status();
179  }
180 
186  services::Status setPartialResult(const PartialResultPtr& partialResult, bool initFlag = false)
187  {
188  DAAL_CHECK(partialResult, services::ErrorNullPartialResult)
189  DAAL_CHECK(partialResult->get(finalResult), services::ErrorNullResult)
190  _partialResult = partialResult;
191  _pres = _partialResult.get();
192  setInitFlag(initFlag);
193  return services::Status();
194  }
195 
200  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
201 
207  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
208  {
209  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
210  }
211 
212 protected:
213  PartialResultPtr _partialResult;
214 
215  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
216  {
217  return new Distributed<step1Local, algorithmFPType, method>(*this);
218  }
219 
220  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
221  {
222  return services::Status();
223  }
224 
225  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
226  {
227  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, (int)method);
228  _pres = _partialResult.get();
229  return s;
230  }
231 
232  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
233  {
234  return services::Status();
235  }
236 
237  void initialize()
238  {
239  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
240  _in = &input;
241  _par = &parameter;
242  _partialResult.reset(new PartialResultType());
243  }
244 
245 };
247 } // interface1
248 using interface1::DistributedContainer;
249 using interface1::Distributed;
250 
251 }
252 }
253 }
254 }
255 }
256 #endif
daal::algorithms::DistributedPrediction
Definition: prediction.h:52
daal
Definition: algorithm_base_common.h:31
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::setResult
services::Status setResult(const ResultPtr &result)
Definition: implicit_als_predict_ratings_distributed.h:173
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:105
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::setPartialResult
services::Status setPartialResult(const PartialResultPtr &partialResult, bool initFlag=false)
Definition: implicit_als_predict_ratings_distributed.h:186
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:255
daal::distributed
Definition: daal_defines.h:107
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed
Runs implicit ALS model-based prediction in the distributed processing mode.
Definition: implicit_als_predict_ratings_distributed.h:102
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_predict_ratings_distributed.h:133
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: implicit_als_predict_ratings_distributed.h:155
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >
Performs implicit ALS model-based prediction in the first step of the distributed processing mode...
Definition: implicit_als_predict_ratings_distributed.h:119
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::clone
services::SharedPtr< Distributed< step1Local, algorithmFPType, method > > clone() const
Definition: implicit_als_predict_ratings_distributed.h:207
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed(const Distributed< step1Local, algorithmFPType, method > &other)
Definition: implicit_als_predict_ratings_distributed.h:144
daal::algorithms::classifier::prediction::prediction
Definition: classifier_predict_types.h:76
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: implicit_als_predict_ratings_distributed.h:127
daal::algorithms::implicit_als::prediction::ratings::interface1::DistributedInput< step1Local >
Input objects for the first step of the rating prediction stage of the implicit ALS algorithm in the ...
Definition: implicit_als_predict_ratings_types.h:200
daal::algorithms::implicit_als::prediction::ratings::interface1::DistributedContainer
Class that contains methods to run implicit ALS model-based prediction in the distributed processing ...
Definition: implicit_als_predict_ratings_distributed.h:52
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::getMethod
virtual int getMethod() const DAAL_C11_OVERRIDE
Definition: implicit_als_predict_ratings_distributed.h:200
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:55
daal::step1Local
Definition: daal_defines.h:117
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: implicit_als_predict_ratings_distributed.h:164
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_predict_ratings_distributed.h:128
daal::algorithms::DistributedPredictionContainerIface
Definition: prediction.h:42
daal::services::ErrorNullResult
Definition: error_indexes.h:96
daal::algorithms::implicit_als::prediction::ratings::finalResult
Definition: implicit_als_predict_ratings_types.h:95

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