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

implicit_als_predict_ratings_distributed.h
1 /* file: implicit_als_predict_ratings_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 implicit ALS model-based ratings prediction
21 // in the distributed processing mode
22 //--
23 */
24 
25 #ifndef __IMPLICIT_ALS_PREDICT_RATINGS_DISTRIBUTED_H__
26 #define __IMPLICIT_ALS_PREDICT_RATINGS_DISTRIBUTED_H__
27 
28 #include "algorithms/algorithm.h"
29 #include "algorithms/implicit_als/implicit_als_predict_ratings_types.h"
30 
31 namespace daal
32 {
33 namespace algorithms
34 {
35 namespace implicit_als
36 {
37 namespace prediction
38 {
39 namespace ratings
40 {
41 
42 namespace interface1
43 {
53 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
54 class DistributedContainer
55 {};
56 
62 template<typename algorithmFPType, Method method, CpuType cpu>
63 class DistributedContainer<step1Local, algorithmFPType, method, cpu> : public DistributedPredictionContainerIface
64 {
65 public:
71  DistributedContainer(daal::services::Environment::env *daalEnv);
72  ~DistributedContainer();
73 
78  services::Status compute() DAAL_C11_OVERRIDE;
83  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
84 };
85 
103 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
104 class Distributed : public daal::algorithms::DistributedPrediction {};
105 
120 template<typename algorithmFPType, Method method>
121 class Distributed<step1Local, algorithmFPType, method> : public daal::algorithms::DistributedPrediction
122 {
123 public:
124  typedef algorithms::implicit_als::prediction::ratings::DistributedInput<step1Local> InputType;
125  typedef algorithms::implicit_als::Parameter ParameterType;
126  typedef algorithms::implicit_als::prediction::ratings::Result ResultType;
127  typedef algorithms::implicit_als::prediction::ratings::PartialResult PartialResultType;
128 
129  DistributedInput<step1Local> input;
130  ParameterType parameter;
135  Distributed()
136  {
137  initialize();
138  }
139 
146  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
147  {
148  initialize();
149  }
150 
151  virtual ~Distributed() {}
152 
157  ResultPtr getResult()
158  {
159  return _partialResult->get(finalResult);
160  }
161 
166  PartialResultPtr getPartialResult()
167  {
168  return _partialResult;
169  }
170 
175  services::Status setResult(const ResultPtr &result)
176  {
177  DAAL_CHECK(result, services::ErrorNullResult)
178  _partialResult->set(finalResult, result);
179  _pres = _partialResult.get();
180  return services::Status();
181  }
182 
188  services::Status setPartialResult(const PartialResultPtr& partialResult, bool initFlag = false)
189  {
190  DAAL_CHECK(partialResult, services::ErrorNullPartialResult)
191  DAAL_CHECK(partialResult->get(finalResult), services::ErrorNullResult)
192  _partialResult = partialResult;
193  _pres = _partialResult.get();
194  setInitFlag(initFlag);
195  return services::Status();
196  }
197 
202  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
203 
209  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
210  {
211  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
212  }
213 
214 protected:
215  PartialResultPtr _partialResult;
216 
217  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
218  {
219  return new Distributed<step1Local, algorithmFPType, method>(*this);
220  }
221 
222  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
223  {
224  return services::Status();
225  }
226 
227  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
228  {
229  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, (int)method);
230  _pres = _partialResult.get();
231  return s;
232  }
233 
234  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
235  {
236  return services::Status();
237  }
238 
239  void initialize()
240  {
241  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
242  _in = &input;
243  _par = &parameter;
244  _partialResult.reset(new PartialResultType());
245  }
246 
247 };
249 } // interface1
250 using interface1::DistributedContainer;
251 using interface1::Distributed;
252 
253 }
254 }
255 }
256 }
257 }
258 #endif
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_predict_ratings_distributed.h:135
daal::step1Local
Definition: daal_defines.h:123
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:146
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:209
daal::algorithms::neural_networks::prediction::prediction
Definition: neural_networks_prediction_result.h:55
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: implicit_als_predict_ratings_distributed.h:157
daal::algorithms::DistributedPredictionContainerIface
Definition: prediction.h:44
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:202
daal::services::ErrorNullResult
Definition: error_indexes.h:98
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: implicit_als_predict_ratings_distributed.h:166
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::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:54
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: implicit_als_predict_ratings_distributed.h:129
daal::algorithms::DistributedPrediction
Definition: prediction.h:54
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:202
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:175
daal::algorithms::implicit_als::prediction::ratings::finalResult
Definition: implicit_als_predict_ratings_types.h:97
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_predict_ratings_distributed.h:130
daal::services::ErrorNullPartialResult
Definition: error_indexes.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:104
daal::distributed
Definition: daal_defines.h:113
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:188
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:121

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