forked from devzhk/LMCTS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_generator.py
38 lines (31 loc) · 1.03 KB
/
data_generator.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
import torch
import yaml
from argparse import ArgumentParser
def generate(config):
num_arm = config['num_arm']
dim_context = config['dim_context']
theta_norm = config['theta_norm']
context_norm = config['context_norm']
T = config['T']
savepath = config['filename']
# generate ground truth theta
theta = torch.randn(dim_context)
theta = theta / torch.norm(theta) * theta_norm
# generate context data
context = torch.randn((T, num_arm, dim_context))
context = context / torch.norm(context, dim=2, keepdim=True) * context_norm
torch.save(
{
'theta': theta,
'context': context
}, savepath
)
print('Data saved at {0}'.format(savepath))
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('--config_path', type=str,
default='configs/data-linear.yaml')
args = parser.parse_args()
with open(args.config_path, 'r') as stream:
config = yaml.load(stream, yaml.FullLoader)
generate(config)