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

implicit_als_predict_ratings_types.h
1 /* file: implicit_als_predict_ratings_types.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 classes used in the rating prediction stage
45 // of the implicit ALS algorithm
46 //--
47 */
48 
49 #ifndef __IMPLICIT_ALS_PREDICT_RATINGS_TYPES_H__
50 #define __IMPLICIT_ALS_PREDICT_RATINGS_TYPES_H__
51 
52 #include "algorithms/algorithm.h"
53 #include "algorithms/implicit_als/implicit_als_model.h"
54 #include "data_management/data/homogen_numeric_table.h"
55 #include "data_management/data/csr_numeric_table.h"
56 
57 namespace daal
58 {
59 namespace algorithms
60 {
61 namespace implicit_als
62 {
72 namespace prediction
73 {
77 namespace ratings
78 {
83 enum Method
84 {
85  defaultDense = 0,
86  allUsersAllItems = 0
87 };
88 
94 enum ModelInputId
95 {
96  model,
97  lastModelInputId = model
98 };
99 
105 enum PartialModelInputId
106 {
107  usersPartialModel,
109  itemsPartialModel,
111  lastPartialModelInputId = itemsPartialModel
112 };
113 
119 enum PartialResultId
120 {
121  finalResult,
122  lastPartialResultId = finalResult
123 };
124 
129 enum ResultId
130 {
131  prediction,
132  lastResultId = prediction
133 };
134 
138 namespace interface1
139 {
140 
145 class InputIface : public daal::algorithms::Input
146 {
147 public:
148  InputIface(size_t nElements) : daal::algorithms::Input(nElements) {}
149  InputIface(const InputIface& other) : daal::algorithms::Input(other) {}
150  virtual ~InputIface() {}
151 
156  virtual size_t getNumberOfUsers() const = 0;
157 
162  virtual size_t getNumberOfItems() const = 0;
163 };
164 
169 class DAAL_EXPORT Input : public InputIface
170 {
171 public:
172  Input();
173  Input(const Input& other) : InputIface(other){}
174  virtual ~Input() {}
175 
181  ModelPtr get(ModelInputId id) const;
182 
188  void set(ModelInputId id, const ModelPtr &ptr);
189 
194  size_t getNumberOfUsers() const DAAL_C11_OVERRIDE;
195 
200  size_t getNumberOfItems() const DAAL_C11_OVERRIDE;
201 
207  services::Status check(const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
208 };
209 
210 
216 template<ComputeStep step>
217 class DistributedInput
218 {};
219 
225 template<>
226 class DAAL_EXPORT DistributedInput<step1Local> : public InputIface
227 {
228 public:
229  DistributedInput();
230  DistributedInput(const DistributedInput& other) : InputIface(other){}
231 
232  virtual ~DistributedInput() {}
233 
239  PartialModelPtr get(PartialModelInputId id) const;
240 
246  void set(PartialModelInputId id, const PartialModelPtr &ptr);
247 
252  size_t getNumberOfUsers() const DAAL_C11_OVERRIDE;
253 
258  size_t getNumberOfItems() const DAAL_C11_OVERRIDE;
259 
265  services::Status check(const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
266 };
267 
268 
274 class DAAL_EXPORT Result : public daal::algorithms::Result
275 {
276 public:
277  DECLARE_SERIALIZABLE_CAST(Result);
278  Result();
279  virtual ~Result()
280  {}
281 
287  data_management::NumericTablePtr get(ResultId id) const;
288 
294  void set(ResultId id, const data_management::NumericTablePtr &ptr);
295 
302  template <typename algorithmFPType>
303  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
304 
311  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
312 
313 protected:
315  template<typename Archive, bool onDeserialize>
316  services::Status serialImpl(Archive *arch)
317  {
318  return daal::algorithms::Result::serialImpl<Archive, onDeserialize>(arch);
319  }
320 };
321 typedef services::SharedPtr<Result> ResultPtr;
322 
327 class DAAL_EXPORT PartialResult : public daal::algorithms::PartialResult
328 {
329 public:
330  DECLARE_SERIALIZABLE_CAST(PartialResult);
332  PartialResult();
334  virtual ~PartialResult() {}
335 
342  template <typename algorithmFPType>
343  DAAL_EXPORT services::Status allocate(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, const int method);
344 
350  ResultPtr get(PartialResultId id) const;
351 
357  void set(PartialResultId id, const ResultPtr &ptr);
358 
365  services::Status check(const daal::algorithms::Input *input, const daal::algorithms::Parameter *parameter, int method) const DAAL_C11_OVERRIDE;
366 
367 protected:
369  template<typename Archive, bool onDeserialize>
370  services::Status serialImpl(Archive *arch)
371  {
372  return daal::algorithms::PartialResult::serialImpl<Archive, onDeserialize>(arch);
373  }
374 };
375 typedef services::SharedPtr<PartialResult> PartialResultPtr;
376 
377 } // interface1
378 using interface1::InputIface;
379 using interface1::Input;
380 using interface1::DistributedInput;
381 using interface1::PartialResult;
382 using interface1::PartialResultPtr;
383 using interface1::Result;
384 using interface1::ResultPtr;
385 
386 }
387 }
389 }
390 }
391 }
392 
393 #endif
daal::algorithms::implicit_als::prediction::ratings::interface1::Input
Input objects for the rating prediction stage of the implicit ALS algorithm
Definition: implicit_als_predict_ratings_types.h:169
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
Definition: algorithm_base_common.h:57
daal::algorithms::implicit_als::prediction::ratings::Method
Method
Definition: implicit_als_predict_ratings_types.h:83
daal::algorithms::interface1::Result
Base class to represent final results of the computation. Algorithm-specific final results are repres...
Definition: algorithm_types.h:331
daal::algorithms::implicit_als::prediction::ratings::itemsPartialModel
Definition: implicit_als_predict_ratings_types.h:109
daal::algorithms::implicit_als::prediction::ratings::PartialResultId
PartialResultId
Definition: implicit_als_predict_ratings_types.h:119
daal::algorithms::interface1::PartialResult
Base class to represent partial results of the computation. Algorithm-specific partial results are re...
Definition: algorithm_types.h:253
daal::algorithms::implicit_als::prediction::ratings::allUsersAllItems
Definition: implicit_als_predict_ratings_types.h:86
daal::algorithms::implicit_als::prediction::ratings::PartialModelInputId
PartialModelInputId
Definition: implicit_als_predict_ratings_types.h:105
daal::algorithms::implicit_als::prediction::ratings::interface1::PartialResult::~PartialResult
virtual ~PartialResult()
Definition: implicit_als_predict_ratings_types.h:334
daal::algorithms::implicit_als::prediction::ratings::usersPartialModel
Definition: implicit_als_predict_ratings_types.h:107
daal::algorithms::implicit_als::prediction::ratings::defaultDense
Definition: implicit_als_predict_ratings_types.h:85
daal::algorithms::implicit_als::prediction::ratings::ModelInputId
ModelInputId
Definition: implicit_als_predict_ratings_types.h:94
daal::algorithms::implicit_als::prediction::ratings::prediction
Definition: implicit_als_predict_ratings_types.h:131
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::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::model
Definition: implicit_als_predict_ratings_types.h:96
daal::algorithms::implicit_als::prediction::ratings::interface1::InputIface::getNumberOfItems
virtual size_t getNumberOfItems() const =0
daal::algorithms::implicit_als::prediction::ratings::ResultId
ResultId
Definition: implicit_als_predict_ratings_types.h:129
daal::algorithms::implicit_als::prediction::ratings::interface1::InputIface
Input interface for the rating prediction stage of the implicit ALS algorithm
Definition: implicit_als_predict_ratings_types.h:145
daal::step1Local
Definition: daal_defines.h:142
daal::algorithms::implicit_als::prediction::ratings::interface1::InputIface::getNumberOfUsers
virtual size_t getNumberOfUsers() const =0
daal::algorithms::interface1::Input
Base class to represent computation input arguments. Algorithm-specific input arguments are represent...
Definition: algorithm_types.h:217
daal::algorithms::implicit_als::prediction::ratings::finalResult
Definition: implicit_als_predict_ratings_types.h:121

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