-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
154 lines (120 loc) · 4.33 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
import tqdm
import pickle
import copy
import data_utils
import argparse
from sklearn.utils import shuffle
import simulation
import simulation.data_utils
import real
import real.data_utils
import numpy as np
from model import Model
import torch
import torch.optim as optim
import torch.nn.functional as F
import pandas as pd
from data_utils import state_dim
from train_utils import train, train_union
import ipdb
import os
# os.environ["CUDA_VISIBLE_DEVICES"] = '0,1,2,3'
# DEVICE = 'cuda:0'
fea_cols = [
'finger_stick', 'meal', 'filled_meal', 'basal', 'bolus'
]
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--latent_dim', type=int, default=128)
parser.add_argument('--epochs', type=int, default=30)
parser.add_argument('--lookback', type=int, default=12)
parser.add_argument('--lookahead', type=int, default=6)
parser.add_argument('--exp', type=str, required=True)
parser.add_argument('--frac', type=float, default=1.0,
help='fraction of real-world data')
args = parser.parse_args()
# data-driven model & expert model
if args.exp in ['expert', 'neural']:
if args.exp == 'expert':
inputs, outputs = simulation.data_utils._get_inputs_outputs(
lookback=args.lookback,
lookahead=args.lookahead,
fea_cols=fea_cols,
filepath='./simulation/data'
)
input_dim = inputs.shape[-1] - 1 - state_dim
use_state = True
elif args.exp == 'neural':
inputs, outputs = real.data_utils._get_inputs_outputs(
lookback=args.lookback,
lookahead=args.lookahead,
fea_cols=fea_cols,
filepath='./real/data/processed',
frac=args.frac
)
input_dim = inputs.shape[-1] - 1
use_state = False
train_dataloader, test_dataloader = data_utils._build_data_loader(
inputs, outputs
)
model, res = train(
args, input_dim, train_dataloader, test_dataloader, use_state=use_state
)
elif args.exp == 'data_aug':
inputs, outputs = real.data_utils._get_inputs_outputs(
lookback=args.lookback,
lookahead=args.lookahead,
fea_cols=fea_cols,
filepath='./real/data/processed',
frac=args.frac
)
inputs_aug, outputs_aug = simulation.data_utils._get_inputs_outputs(
lookback=args.lookback,
lookahead=args.lookahead,
fea_cols=fea_cols,
filepath='./simulation/data'
)
input_dim = inputs.shape[-1] - 1
train_dataloader, test_dataloader = data_utils._build_data_loader_aug(
inputs=inputs,
outputs=outputs,
inputs_aug=inputs_aug,
outputs_aug=outputs_aug
)
model, res = train(
args, input_dim, train_dataloader, test_dataloader, use_state=True
)
elif args.exp == 'fine_tune':
expert_model = torch.load(f'./results/model/expert.model')
inputs, outputs = real.data_utils._get_inputs_outputs(
lookback=args.lookback,
lookahead=args.lookahead,
fea_cols=fea_cols,
filepath='./real/data/processed',
frac=args.frac
)
input_dim = inputs.shape[-1] - 1
train_dataloader, test_dataloader = data_utils._build_data_loader(
inputs=inputs,
outputs=outputs,
)
model, res = train(
args, input_dim, train_dataloader, test_dataloader, use_state=False, base_model=expert_model, disable_train=True
)
elif args.exp == 'union':
expert_model = torch.load(f'./results/model/expert.model')
inputs, outputs = real.data_utils._get_inputs_outputs(
lookback=args.lookback,
lookahead=args.lookahead,
fea_cols=fea_cols,
filepath='./real/data/processed',
frac=args.frac
)
input_dim = inputs.shape[-1] - 1
train_dataloader, test_dataloader = data_utils._build_data_loader(
inputs=inputs,
outputs=outputs,
)
model, res = train_union(
args, input_dim, train_dataloader, test_dataloader, expert_model=expert_model
)