MLPACK
1.0.10
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
src
mlpack
methods
cf
cf.hpp
Go to the documentation of this file.
1
25
#ifndef __MLPACK_METHODS_CF_CF_HPP
26
#define __MLPACK_METHODS_CF_CF_HPP
27
28
#include <
mlpack/core.hpp
>
29
#include <
mlpack/methods/neighbor_search/neighbor_search.hpp
>
30
#include <
mlpack/methods/amf/amf.hpp
>
31
#include <
mlpack/methods/amf/update_rules/nmf_als.hpp
>
32
#include <
mlpack/methods/amf/termination_policies/simple_residue_termination.hpp
>
33
#include <set>
34
#include <map>
35
#include <iostream>
36
37
namespace
mlpack {
38
namespace
cf {
39
72
template
<
73
typename
FactorizerType =
amf::AMF
<
amf::SimpleResidueTermination
,
74
amf::RandomInitialization
,
75
amf::NMFALSUpdate
> >
76
class
CF
77
{
78
public
:
89
CF
(arma::mat&
data
,
90
const
size_t
numUsersForSimilarity
= 5,
91
const
size_t
rank
= 0);
92
94
void
NumUsersForSimilarity
(
const
size_t
num)
95
{
96
if
(num < 1)
97
{
98
Log::Warn
<<
"CF::NumUsersForSimilarity(): invalid value (< 1) "
99
"ignored."
<< std::endl;
100
return
;
101
}
102
this->
numUsersForSimilarity
= num;
103
}
104
106
size_t
NumUsersForSimilarity
()
const
107
{
108
return
numUsersForSimilarity
;
109
}
110
112
void
Rank
(
const
size_t
rankValue)
113
{
114
this->
rank
= rankValue;
115
}
116
118
size_t
Rank
()
const
119
{
120
return
rank
;
121
}
122
124
void
Factorizer
(
const
FactorizerType& f)
125
{
126
this->
factorizer
= f;
127
}
128
130
const
arma::mat&
W
()
const
{
return
w
; }
132
const
arma::mat&
H
()
const
{
return
h
; }
134
const
arma::mat&
Rating
()
const
{
return
rating
; }
136
const
arma::mat&
Data
()
const
{
return
data
; }
138
const
arma::sp_mat&
CleanedData
()
const
{
return
cleanedData
; }
139
146
void
GetRecommendations
(
const
size_t
numRecs,
147
arma::Mat<size_t>& recommendations);
148
156
void
GetRecommendations
(
const
size_t
numRecs,
157
arma::Mat<size_t>& recommendations,
158
arma::Col<size_t>& users);
159
163
std::string
ToString
()
const
;
164
165
private
:
167
arma::mat
data
;
169
size_t
numUsersForSimilarity
;
171
size_t
rank
;
173
FactorizerType
factorizer
;
175
arma::mat
w
;
177
arma::mat
h
;
179
arma::mat
rating
;
181
arma::sp_mat
cleanedData
;
183
void
CleanData
();
184
194
void
InsertNeighbor
(
const
size_t
queryIndex,
195
const
size_t
pos,
196
const
size_t
neighbor,
197
const
double
value,
198
arma::Mat<size_t>& recommendations,
199
arma::mat& values)
const
;
200
201
};
// class CF
202
203
};
// namespace cf
204
};
// namespace mlpack
205
206
//Include implementation
207
#include "cf_impl.hpp"
208
209
#endif
Generated by
1.8.3.1