-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.m
57 lines (47 loc) · 1.58 KB
/
test.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
%training set
R = getfield(load('train_amazon.mat','train_amazon_Matrix'),'train_amazon_Matrix');
%R = getfield(load('train_yelp.mat','train_yelp_Matrix'),'train_yelp_Matrix');
%form FMs model feature vectors from transaction data
[userId,itemId,y] = find(R);
num = length(y);
userX = sparse(1:num,userId,ones(num,1));
itemX = sparse(1:num,itemId,ones(num,1));
F = getfield(load('feature_amazon.mat','feature_amazon_Matrix'),'feature_amazon_Matrix');
%F = getfield(load('feature_yelp.mat','feature_yelp_Matrix'),'feature_yelp_Matrix');
if size(F,2) > 100
h = sum(F);
[~,top] = sort(h,'descend');
F = F(:,top(1:100));
end
d = sum(F,2);
dIDX = (d == 0);
F = bsxfun(@rdivide,F,d);
F(dIDX,:) = 0;
fX = F(itemId,:);
%define the dimensionality of the factorization
k = 64;
%define the tunning parameter
alpha = 0;
beta = 10;
%apply initialization
option.init = true;
option.debug = true;
%number of iterations
option.maxItr = 20;
[w0,w,userU,itemU,U3,userZ,itemZ,Z3] = DFM(userX,itemX,fX, y,F,k,alpha,beta,option);
%evaluation measure NDCG
%test set
S = getfield(load('test_amazon.mat','test_amazon_Matrix'),'test_amazon_Matrix');
%S = getfield(load('test_yelp.mat','test_yelp_Matrix'),'test_yelp_Matrix');
[userId2,itemId2,y2] = find(S);
num2 = length(y2);
userX2 = sparse(1:num2,userId2,ones(1,num2));
itemX2 = sparse(1:num2,itemId2,ones(1,num2));
fX2 = F(itemId2,:);
ndcg = zeros(10,1);
for kvalue = 1:10
[ndcgvalue] = NDCG(userX2,itemX2,fX2, y2, F, w0,w,userU,itemU,U3,kvalue);
ndcg(kvalue) = ndcgvalue;
disp(['The DFM ndcg@',int2str(kvalue),' is ',num2str(ndcgvalue)]);
end
plot(ndcg);