-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
158 lines (121 loc) · 4.31 KB
/
main.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
import click
from automation.config import *
from automation.interactive import *
from automation.paper import paper_figures
from automation.msd_dataset import MsdDataset
from automation.msd_dataset import DeleteAllModelFigures
from automation.msd_dataset import DeleteAllModelAnalysis
@click.group()
@click.option(
'--n-users',
default=10_000,
type=int,
help='Number of users to sample from the datasest'
)
@click.option(
'--local-scheduler',
default=False,
type=bool,
help='Use a luigi local scheduler for the tasks execution'
)
@click.option(
'--name',
default='MSD-10_000-users',
type=str,
help='The name of the folder where to save the experiments'
)
@click.pass_context
def cli(context: click.Context, n_users, local_scheduler, name):
context.ensure_object(dict)
context.obj['n_users'] = n_users
context.obj['local_scheduler'] = local_scheduler
context.obj['name'] = name
@cli.command()
@click.pass_context
def report_figures(context):
"""Lauch luigi to generate the report figures"""
n_users = context.obj['n_users']
local_scheduler = context.obj['local_scheduler']
name = context.obj['name']
tasks = paper_figures(n_users, name)
luigi.build(tasks, local_scheduler=local_scheduler,
log_level='INFO', scheduler_host='127.0.0.1')
@cli.command()
@click.pass_context
def clean_models(context):
"""Keep the models, clear the models' folders"""
n_users = context.obj['n_users']
local_scheduler = context.obj['local_scheduler']
name = context.obj['name']
msd_dataset = MsdDataset(name, n_users=n_users)
task = DeleteAllModelAnalysis(dataset=msd_dataset)
for file in task.will_delete():
print(f'\t{file}')
input('ARE YOU SURE YOU WANT TO DELETE THE FILES ? Press Enter to continue')
luigi.build([task], local_scheduler=local_scheduler,
log_level='INFO', scheduler_host='127.0.0.1')
@cli.command()
@click.pass_context
def clear_figures(context):
"""Clear the generated figures"""
n_users = context.obj['n_users']
local_scheduler = context.obj['local_scheduler']
name = context.obj['name']
msd_dataset = MsdDataset(name, n_users=n_users)
task = DeleteAllModelFigures(dataset=msd_dataset)
for file in task.will_delete():
print(f'\t{file}')
input('ARE YOU SURE YOU WANT TO DELETE THE FILES ? Press Enter to continue')
luigi.build([task], local_scheduler=local_scheduler,
log_level='INFO', scheduler_host='127.0.0.1')
@cli.group()
@click.option(
'--animated',
type=click.Choice(['latent-factors', 'reco-volume']),
default='reco-volume',
help='Choose the variable to change during the animation'
)
@click.option(
'--alpha',
type=float,
default=2,
help='The order of the diversity to use.'
)
@click.pass_context
def interactive(context: click.Context, animated: str, alpha: float):
"""Lauch the interactive graphs server"""
context.ensure_object(dict)
# Avoid issues where 0.0 and 0 lead to different file titles
alpha = float(alpha)
alpha = int(alpha) if alpha.is_integer() else alpha
context.obj['animated'] = animated
context.obj['alpha'] = alpha
@interactive.command()
@click.pass_context
def recommendation_diversity(context):
n_users = context.obj['n_users']
local_scheduler = context.obj['local_scheduler']
name = context.obj['name']
animated = context.obj['animated']
msd_dataset = MsdDataset(name, n_users=n_users)
if animated == 'latent-factors':
reco_div_vs_user_div_vs_latent_factors(msd_dataset, local_scheduler)
elif animated == 'reco-volume':
reco_div_vs_user_div_vs_reco_volume(msd_dataset, local_scheduler)
@interactive.command()
@click.pass_context
def diversity_increase(context):
n_users = context.obj['n_users']
local_scheduler = context.obj['local_scheduler']
name = context.obj['name']
animated = context.obj['animated']
alpha = context.obj['alpha']
msd_dataset = MsdDataset(name, n_users=n_users)
if animated == 'latent-factors':
div_increase_vs_user_div_vs_latent_factors(
msd_dataset, local_scheduler, alpha)
elif animated == 'reco-volume':
div_increase_vs_user_div_vs_reco_volume(
msd_dataset, local_scheduler, alpha)
if __name__ == '__main__':
cli(obj={})