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

implicit_als_model.h
1 /* file: implicit_als_model.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 // Declaration of the implicit ALS model class
21 //--
22 */
23 
24 #ifndef __IMPLICIT_ALS_MODEL_H__
25 #define __IMPLICIT_ALS_MODEL_H__
26 
27 #include "algorithms/model.h"
28 #include "data_management/data/homogen_numeric_table.h"
29 
30 namespace daal
31 {
32 namespace algorithms
33 {
43 namespace implicit_als
44 {
45 
49 namespace interface1
50 {
57 /* [Parameter source code] */
58 struct DAAL_EXPORT Parameter : public daal::algorithms::Parameter
59 {
68  Parameter(size_t nFactors = 10, size_t maxIterations = 5, double alpha = 40.0, double lambda = 0.01,
69  double preferenceThreshold = 0.0) :
70  nFactors(nFactors), maxIterations(maxIterations), alpha(alpha), lambda(lambda),
71  preferenceThreshold(preferenceThreshold)
72  {}
73 
74  size_t nFactors;
75  size_t maxIterations;
76  double alpha;
77  double lambda;
78  double preferenceThreshold;
80  services::Status check() const DAAL_C11_OVERRIDE;
81 };
82 /* [Parameter source code] */
83 
92 class DAAL_EXPORT Model : public daal::algorithms::Model
93 {
94 
95 public:
96  DECLARE_MODEL(Model, daal::algorithms::Model);
97 
106  template<typename modelFPType>
107  DAAL_EXPORT Model(size_t nUsers, size_t nItems, const Parameter &parameter, modelFPType dummy);
108 
113  Model();
114 
122  template<typename modelFPType>
123  DAAL_EXPORT static services::SharedPtr<Model> create(size_t nUsers, size_t nItems,
124  const Parameter &parameter,
125  services::Status *stat = NULL);
126 
127  virtual ~Model() { }
128 
134  data_management::NumericTablePtr getUsersFactors() const { return _usersFactors; }
135 
141  data_management::NumericTablePtr getItemsFactors() const { return _itemsFactors; }
142 
143 private:
144  data_management::NumericTablePtr _usersFactors; /* Table of resulting users factors */
145  data_management::NumericTablePtr _itemsFactors; /* Table of resulting items factors */
146 
147 protected:
148 
149  template<typename Archive, bool onDeserialize>
150  services::Status serialImpl(Archive *arch)
151  {
152  daal::algorithms::Model::serialImpl<Archive, onDeserialize>(arch);
153 
154  arch->setSharedPtrObj(_usersFactors);
155  arch->setSharedPtrObj(_itemsFactors);
156 
157  return services::Status();
158  }
159 
160  template<typename modelFPType>
161  DAAL_EXPORT Model(size_t nUsers, size_t nItems, const Parameter &parameter,
162  modelFPType dummy, services::Status &st);
163 
164 };
165 typedef services::SharedPtr<Model> ModelPtr;
166 
175 class DAAL_EXPORT PartialModel : public daal::algorithms::Model
176 {
177 public:
178  DECLARE_SERIALIZABLE_CAST(PartialModel);
179 
187  template<typename modelFPType>
188  DAAL_EXPORT PartialModel(const Parameter &parameter, size_t size, modelFPType dummy);
189 
198  template<typename modelFPType>
199  DAAL_EXPORT PartialModel(const Parameter &parameter, size_t offset,
200  data_management::NumericTablePtr indices, modelFPType dummy);
201 
208  PartialModel(data_management::NumericTablePtr factors,
209  data_management::NumericTablePtr indices);
210 
215  PartialModel();
216 
224  template<typename modelFPType>
225  DAAL_EXPORT static services::SharedPtr<PartialModel> create(const Parameter &parameter, size_t size,
226  services::Status *stat = NULL);
235  template<typename modelFPType>
236  DAAL_EXPORT static services::SharedPtr<PartialModel> create(const Parameter &parameter, size_t offset,
237  const data_management::NumericTablePtr &indices,
238  services::Status *stat = NULL);
246  static services::SharedPtr<PartialModel> create(const data_management::NumericTablePtr &factors,
247  const data_management::NumericTablePtr &indices,
248  services::Status *stat = NULL);
249 
250  virtual ~PartialModel() { }
251 
256  data_management::NumericTablePtr getFactors() const { return _factors; }
257 
262  data_management::NumericTablePtr getIndices() const { return _indices; }
263 
264 protected:
265  data_management::NumericTablePtr _factors; /* Factors in row-major format */
266  data_management::NumericTablePtr _indices; /* Indices of the factors */
267 
268  template<typename Archive, bool onDeserialize>
269  services::Status serialImpl(Archive *arch)
270  {
271  daal::algorithms::Model::serialImpl<Archive, onDeserialize>(arch);
272 
273  arch->setSharedPtrObj(_factors);
274  arch->setSharedPtrObj(_indices);
275 
276  return services::Status();
277  }
278 
279  template<typename modelFPType>
280  DAAL_EXPORT PartialModel(const Parameter &parameter, size_t size, modelFPType dummy, services::Status &st);
281 
282  template<typename modelFPType>
283  DAAL_EXPORT PartialModel(const Parameter &parameter, size_t offset,
284  const data_management::NumericTablePtr &indices,
285  modelFPType dummy, services::Status &st);
286 
287  PartialModel(const data_management::NumericTablePtr &factors,
288  const data_management::NumericTablePtr &indices,
289  services::Status &st);
290 
291 private:
292  template<typename modelFPType>
293  DAAL_EXPORT services::Status initialize(const Parameter &parameter, size_t size);
294 
295  template<typename modelFPType>
296  DAAL_EXPORT services::Status initialize(const Parameter &parameter, size_t offset,
297  const data_management::NumericTablePtr &indices);
298 };
299 
300 typedef services::SharedPtr<PartialModel> PartialModelPtr;
301 } // namespace interface1
302 using interface1::Parameter;
303 using interface1::ModelPtr;
304 using interface1::Model;
305 using interface1::PartialModelPtr;
306 using interface1::PartialModel;
307 
308 }
310 }
311 }
312 
313 #endif
daal::algorithms::implicit_als::interface1::PartialModel::getIndices
data_management::NumericTablePtr getIndices() const
Definition: implicit_als_model.h:262
daal::algorithms::implicit_als::interface1::Parameter::Parameter
Parameter(size_t nFactors=10, size_t maxIterations=5, double alpha=40.0, double lambda=0.01, double preferenceThreshold=0.0)
Definition: implicit_als_model.h:68
daal::algorithms::implicit_als::interface1::Parameter::lambda
double lambda
Definition: implicit_als_model.h:77
daal::algorithms::implicit_als::interface1::Parameter::maxIterations
size_t maxIterations
Definition: implicit_als_model.h:75
daal::algorithms::implicit_als::interface1::Parameter::alpha
double alpha
Definition: implicit_als_model.h:76
daal::algorithms::implicit_als::interface1::PartialModel
Partial model trained by the implicit ALS training algorithm in the distributed processing mode...
Definition: implicit_als_model.h:175
daal::algorithms::implicit_als::interface1::Model::getUsersFactors
data_management::NumericTablePtr getUsersFactors() const
Definition: implicit_als_model.h:134
daal::algorithms::implicit_als::interface1::Parameter::preferenceThreshold
double preferenceThreshold
Definition: implicit_als_model.h:78
daal::algorithms::implicit_als::interface1::PartialModel::getFactors
data_management::NumericTablePtr getFactors() const
Definition: implicit_als_model.h:256
daal::algorithms::implicit_als::interface1::Model
Model trained by the implicit ALS algorithm in the batch processing mode.
Definition: implicit_als_model.h:92
daal::algorithms::implicit_als::interface1::Model::getItemsFactors
data_management::NumericTablePtr getItemsFactors() const
Definition: implicit_als_model.h:141
daal::algorithms::implicit_als::interface1::Parameter
Parameters for the compute() method of the implicit ALS algorithm.
Definition: implicit_als_model.h:58
daal::algorithms::implicit_als::interface1::Parameter::nFactors
size_t nFactors
Definition: implicit_als_model.h:74

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