-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patht_best_step.py
51 lines (45 loc) · 1.74 KB
/
t_best_step.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
from pyrec.data import UIRData
from pyrec.inventory import Inventory
from pyrec.sims.rand import BestSimulator
from pyrec.parallel import MultiSimulator
from pyrec.plots import multi_success_stops
from pyrec.recs.mf import MatrixFactorization, NNMatrixFactorization, \
RandomMatrixFactorization, UnbiasedMatrixFactorization
from pyrec.recs.inv import MostInInvStaticRecommender, MostInInvRecommender
from pyrec.recs.weighted import WeightedRecommender
uir_data = UIRData.from_csv("../data/podatki/ratings_inv_norm.csv")
inv = Inventory.from_csv("../data/podatki/inv_norm.csv")
figure_file = "../figures/t"
k = 30
n = 800_000
rec_kwargs = {"verbose": True, "max_iteration": 10, "batch_size": 1000,
"rec": MatrixFactorization,
"rec_kwargs": {"max_iteration": 10, "batch_size": 1000},
"walpha": 0.5, "rec1": MatrixFactorization,
"rec1_kwargs": {"max_iteration": 10, "batch_size": 1000},
"rec2": MostInInvRecommender, "rec2_kwargs": {}}
sim_kwargs = {"verbose": True}
recs = [
("rand", RandomMatrixFactorization),
("miis", MostInInvStaticRecommender),
("mii", MostInInvRecommender),
("umf", UnbiasedMatrixFactorization),
("w(a=0.5)", WeightedRecommender),
("mf", MatrixFactorization),
("nnmf", NNMatrixFactorization),
]
sims = []
for name, rec in recs:
inv = Inventory(uir_data)
rec_kwargs["inv"] = inv
rec_kwargs["rec2_kwargs"]["inv"] = inv
r = rec(**rec_kwargs)
r.fit(uir_data)
sims.append(BestSimulator(name, uir_data, r, inv))
# run simulations
print("run simulations")
ms = MultiSimulator(n)
ms.set_sims(sims)
ms.run_parallel()
multi_success_stops(sims, list(range(1_000, n + 1, 1_000)),
save_file=figure_file + "_best_step.svg")