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

implicit_als_predict_ratings_distributed.h
1 /* file: implicit_als_predict_ratings_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 implicit ALS model-based ratings prediction
45 // in the distributed processing mode
46 //--
47 */
48 
49 #ifndef __IMPLICIT_ALS_PREDICT_RATINGS_DISTRIBUTED_H__
50 #define __IMPLICIT_ALS_PREDICT_RATINGS_DISTRIBUTED_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "algorithms/implicit_als/implicit_als_predict_ratings_types.h"
54 
55 namespace daal
56 {
57 namespace algorithms
58 {
59 namespace implicit_als
60 {
61 namespace prediction
62 {
63 namespace ratings
64 {
65 
66 namespace interface1
67 {
77 template<ComputeStep step, typename algorithmFPType, Method method, CpuType cpu>
78 class DAAL_EXPORT DistributedContainer
79 {};
80 
86 template<typename algorithmFPType, Method method, CpuType cpu>
87 class DAAL_EXPORT DistributedContainer<step1Local, algorithmFPType, method, cpu> : public DistributedPredictionContainerIface
88 {
89 public:
95  DistributedContainer(daal::services::Environment::env *daalEnv);
96  ~DistributedContainer();
97 
102  services::Status compute() DAAL_C11_OVERRIDE;
107  services::Status finalizeCompute() DAAL_C11_OVERRIDE;
108 };
109 
127 template<ComputeStep step, typename algorithmFPType = DAAL_ALGORITHM_FP_TYPE, Method method = defaultDense>
128 class Distributed : public daal::algorithms::DistributedPrediction {};
129 
144 template<typename algorithmFPType, Method method>
145 class Distributed<step1Local, algorithmFPType, method> : public daal::algorithms::DistributedPrediction
146 {
147 public:
148  typedef algorithms::implicit_als::prediction::ratings::DistributedInput<step1Local> InputType;
149  typedef algorithms::implicit_als::Parameter ParameterType;
150  typedef algorithms::implicit_als::prediction::ratings::Result ResultType;
151  typedef algorithms::implicit_als::prediction::ratings::PartialResult PartialResultType;
152 
153  DistributedInput<step1Local> input;
154  ParameterType parameter;
159  Distributed()
160  {
161  initialize();
162  }
163 
170  Distributed(const Distributed<step1Local, algorithmFPType, method> &other) : input(other.input), parameter(other.parameter)
171  {
172  initialize();
173  }
174 
175  virtual ~Distributed() {}
176 
181  ResultPtr getResult()
182  {
183  return _partialResult->get(finalResult);
184  }
185 
190  PartialResultPtr getPartialResult()
191  {
192  return _partialResult;
193  }
194 
199  services::Status setResult(const ResultPtr &result)
200  {
201  DAAL_CHECK(result, services::ErrorNullResult)
202  _partialResult->set(finalResult, result);
203  _pres = _partialResult.get();
204  return services::Status();
205  }
206 
212  services::Status setPartialResult(const PartialResultPtr& partialResult, bool initFlag = false)
213  {
214  DAAL_CHECK(partialResult, services::ErrorNullPartialResult)
215  DAAL_CHECK(partialResult->get(finalResult), services::ErrorNullResult)
216  _partialResult = partialResult;
217  _pres = _partialResult.get();
218  setInitFlag(initFlag);
219  return services::Status();
220  }
221 
226  virtual int getMethod() const DAAL_C11_OVERRIDE { return(int)method; }
227 
233  services::SharedPtr<Distributed<step1Local, algorithmFPType, method> > clone() const
234  {
235  return services::SharedPtr<Distributed<step1Local, algorithmFPType, method> >(cloneImpl());
236  }
237 
238 protected:
239  PartialResultPtr _partialResult;
240 
241  virtual Distributed<step1Local, algorithmFPType, method> * cloneImpl() const DAAL_C11_OVERRIDE
242  {
243  return new Distributed<step1Local, algorithmFPType, method>(*this);
244  }
245 
246  virtual services::Status allocateResult() DAAL_C11_OVERRIDE
247  {
248  return services::Status();
249  }
250 
251  virtual services::Status allocatePartialResult() DAAL_C11_OVERRIDE
252  {
253  services::Status s = _partialResult->allocate<algorithmFPType>(&input, &parameter, (int)method);
254  _pres = _partialResult.get();
255  return s;
256  }
257 
258  virtual services::Status initializePartialResult() DAAL_C11_OVERRIDE
259  {
260  return services::Status();
261  }
262 
263  void initialize()
264  {
265  _ac = new __DAAL_ALGORITHM_CONTAINER(distributed, DistributedContainer, step1Local, algorithmFPType, method)(&_env);
266  _in = &input;
267  _par = &parameter;
268  _partialResult.reset(new PartialResultType());
269  }
270 
271 };
273 } // interface1
274 using interface1::DistributedContainer;
275 using interface1::Distributed;
276 
277 }
278 }
279 }
280 }
281 }
282 #endif
daal::algorithms::DistributedPrediction
Definition: prediction.h:78
daal::algorithms::implicit_als::prediction::ratings::interface1::Result
Provides methods to access the prediction results obtained with the compute() method of the implicit ...
Definition: implicit_als_predict_ratings_types.h:274
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::interface1::Parameter
Parameters for the compute() method of the implicit ALS algorithm.
Definition: implicit_als_model.h:82
daal::algorithms::neural_networks::prediction::prediction
Definition: neural_networks_prediction_result.h:79
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:199
daal::services::ErrorNullPartialResult
Definition: error_indexes.h:131
daal::algorithms::implicit_als::prediction::ratings::finalResult
Definition: implicit_als_predict_ratings_types.h:121
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:212
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::distributed
Definition: daal_defines.h:133
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:233
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:128
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::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::Distributed
Distributed()
Definition: implicit_als_predict_ratings_distributed.h:159
daal::services::interface1::SharedPtr::reset
void reset()
Definition: daal_shared_ptr.h:265
daal::algorithms::implicit_als::prediction::ratings::interface1::PartialResult
Provides methods to access partial results obtained with the compute() method of the implicit ALS ini...
Definition: implicit_als_predict_ratings_types.h:327
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::getResult
ResultPtr getResult()
Definition: implicit_als_predict_ratings_distributed.h:181
daal::algorithms::implicit_als::prediction::ratings::interface1::DistributedInput
Input objects for the rating prediction stage of the implicit ALS algorithm in the distributed proces...
Definition: implicit_als_predict_ratings_types.h:217
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:145
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:170
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::input
DistributedInput< step1Local > input
Definition: implicit_als_predict_ratings_distributed.h:153
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:226
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:78
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:226
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::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::getPartialResult
PartialResultPtr getPartialResult()
Definition: implicit_als_predict_ratings_distributed.h:190
daal::algorithms::implicit_als::prediction::ratings::interface1::Distributed< step1Local, algorithmFPType, method >::parameter
ParameterType parameter
Definition: implicit_als_predict_ratings_distributed.h:154
daal::algorithms::DistributedPredictionContainerIface
Definition: prediction.h:68
daal::services::ErrorNullResult
Definition: error_indexes.h:122

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