-
Notifications
You must be signed in to change notification settings - Fork 1
/
script_dcpf_TPS.py
165 lines (141 loc) · 5.47 KB
/
script_dcpf_TPS.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
@author: ogouvert
This script will reproduce results from the article:
"Recommendation from Raw Data with Adaptive Compound Poisson Factorization",
for the Taste Profile Subset.
"""
#%% READ
import numpy as np
import cPickle as pickle
from function.train_test import divide_train_test
from model.dcpf_Log import dcpf_Log
from model.dcpf_ZTP import dcpf_ZTP
from model.dcpf_Geo import dcpf_Geo
from model.dcpf_sNB import dcpf_sNB
#%% DATA
seed_test = 1992
prop_test = 0.2
# pre-processed data
with open('data/tps/tps_12345_U1.63e+04_I1.21e+04_min_uc20_sc20', 'rb') as f:
out = pickle.load(f)
Y = out['Y_listen']
Y_train,Y_test = divide_train_test(Y,prop_test=prop_test,seed=seed_test)
#%%
Seed = [1404, 2510, 9876, 6060, 4892] # Seed of the different initializations
Ks = [100] # Number of latent factors
alphas = [.3] # shape parameter of the gamma priors of W and H
# Note that limit cases: PF on raw data and PF on binarized data are obtained,
# for example, when p=0 or p=1 for dcpf with Log
tol=0
min_iter = max_iter = 10**3
save_dir = 'out/tps'
####################
#%% dcPF: Log
####################
if True:
opt_hyper = ['beta']
for seed in Seed:
for p in np.linspace(0,1.,11): # Grid-search
for K in Ks:
for alpha in alphas:
model = dcpf_Log(K=K, p=p, alphaW=alpha,alphaH=alpha)
model.fit(Y_train, opt_hyper=opt_hyper, seed=seed,
precision=tol, min_iter=min_iter, max_iter=max_iter,
save=True, save_dir=save_dir,prefix='tps',
verbose=False)
print '+1'
if True:
opt_hyper = ['p','beta']
p = 0.5
for seed in Seed:
for K in Ks:
for alpha in alphas:
model = dcpf_Log(K=K, p=p, alphaW=alpha,alphaH=alpha)
model.fit(Y_train, opt_hyper=opt_hyper, seed=seed,
precision=tol, min_iter=min_iter, max_iter=max_iter,
save=True, save_dir=save_dir,prefix='tps',
verbose=True)
print '+1'
####################
#%% dcPF: ZTP
####################
if True:
opt_hyper = ['beta']
for seed in Seed:
for p in [0.,.1,.5,1.,2.,5.,10.,float('inf')]: # Grid-search
for K in Ks:
for alpha in alphas:
model = dcpf_ZTP(K=K, p=p, alphaW=alpha,alphaH=alpha)
model.fit(Y_train, opt_hyper=opt_hyper, seed=seed,
precision=tol, min_iter=min_iter, max_iter=max_iter,
save=True, save_dir=save_dir,prefix='tps',
verbose=False)
print '+1'
if True:
opt_hyper = ['p','beta']
p = 1.
for seed in Seed:
for K in Ks:
for alpha in alphas:
model = dcpf_ZTP(K=K, p=p, alphaW=alpha,alphaH=alpha)
model.fit(Y_train, opt_hyper=opt_hyper, seed=seed,
precision=tol, min_iter=min_iter, max_iter=max_iter,
save=True, save_dir=save_dir,prefix='tps',
verbose=False)
print '+1'
####################
#%% dcPF: Geo
####################
if True:
opt_hyper = ['beta']
for seed in Seed:
for p in np.linspace(0,1.,11): # Grid-search
for K in Ks:
for alpha in alphas:
model = dcpf_Geo(K=K, p=p, alphaW=alpha,alphaH=alpha)
model.fit(Y_train, opt_hyper=opt_hyper, seed=seed,
precision=tol, min_iter=min_iter, max_iter=max_iter,
save=True, save_dir=save_dir,prefix='tps',
verbose=False)
print '+1'
if True:
opt_hyper = ['p','beta']
p = .5
for seed in Seed:
for K in Ks:
for alpha in alphas:
model = dcpf_Geo(K=K, p=p, alphaW=alpha,alphaH=alpha)
model.fit(Y_train, opt_hyper=opt_hyper, seed=seed,
precision=tol, min_iter=min_iter, max_iter=max_iter,
save=True, save_dir=save_dir,prefix='tps',
verbose=False)
print '+1'
####################
#%% dcPF: Geo
####################
if True:
opt_hyper = ['beta']
for seed in Seed:
for p in np.linspace(0,1.,11): # Grid-search
for K in Ks:
for alpha in alphas:
model = dcpf_sNB(K=K, p=p, alphaW=alpha,alphaH=alpha)
model.fit(Y_train, opt_hyper=opt_hyper, seed=seed,
precision=tol, min_iter=min_iter, max_iter=max_iter,
save=True, save_dir=save_dir,prefix='tps',
verbose=False)
print '+1'
if True:
opt_hyper = ['p','beta']
p = .5
for seed in Seed:
for K in Ks:
for alpha in alphas:
model = dcpf_sNB(K=K, p=p, alphaW=alpha,alphaH=alpha)
model.fit(Y_train, opt_hyper=opt_hyper, seed=seed,
precision=tol, min_iter=min_iter, max_iter=max_iter,
save=True, save_dir=save_dir,prefix='tps',
verbose=False)
print '+1'