forked from wang-fujin/PINN4SOH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_HUST.py
94 lines (75 loc) · 3.94 KB
/
main_HUST.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
from dataloader.dataloader import XJTUdata,MITdata,HUSTdata,TJUdata
from Model.Model import PINN
import argparse
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '1'
def get_args():
parser = argparse.ArgumentParser('Hyper Parameters for HUST dataset')
parser.add_argument('--data', type=str, default='HUST', help='XJTU, HUST, MIT, TJU')
parser.add_argument('--batch_size', type=int, default=512, help='batch size')
parser.add_argument('--normalization_method', type=str, default='min-max', help='min-max,z-score')
# scheduler related
parser.add_argument('--epochs', type=int, default=200, help='epoch')
parser.add_argument('--early_stop', type=int, default=20, help='early stop')
parser.add_argument('--warmup_epochs', type=int, default=30, help='warmup epoch')
parser.add_argument('--warmup_lr', type=float, default=2e-3, help='warmup lr')
parser.add_argument('--lr', type=float, default=1e-2, help='learning rate')
parser.add_argument('--final_lr', type=float, default=2e-4, help='final lr')
parser.add_argument('--lr_F', type=float, default=5e-4, help='lr of F')
# model related
# parser.add_argument('--u_layers_num', type=int, default=3, help='the layers num of u')
# parser.add_argument('--u_hidden_dim', type=int, default=60, help='the hidden dim of u')
parser.add_argument('--F_layers_num', type=int, default=3, help='the layers num of F')
parser.add_argument('--F_hidden_dim', type=int, default=60, help='the hidden dim of F')
# loss related
parser.add_argument('--alpha', type=float, default=0.5, help='loss = l_data + alpha * l_PDE + beta * l_physics')
parser.add_argument('--beta', type=float, default=0.2, help='loss = l_data + alpha * l_PDE + beta * l_physics')
parser.add_argument('--log_dir', type=str, default='logging.txt', help='log dir, if None, do not save')
parser.add_argument('--save_folder', type=str, default='results/HUST results', help='save folder')
args = parser.parse_args()
return args
def load_HUST_data(args,small_sample=None):
test_id = ['1-4','1-8','2-4','2-8',
'3-4','3-8','4-4','4-8',
'5-4','5-7','6-4','6-8',
'7-4','7-8','8-4','8-8',
'9-4','9-8','10-4','10-8']
data = HUSTdata(root='data/HUST data',args=args)
train_list = []
test_list = []
files = os.listdir('data/HUST data')
for f in files:
if f[:-4] in test_id:
test_list.append(f'data/HUST data/{f}')
else:
train_list.append(f'data/HUST data/{f}')
if small_sample is not None:
train_list = train_list[:small_sample]
trainloader = data.read_all(specific_path_list=train_list)
testloader = data.read_all(specific_path_list=test_list)
dataloader = {'train':trainloader['train_2'],'valid':trainloader['valid_2'],'test':testloader['test_3']}
return dataloader
def main():
args = get_args()
for e in range(10):
setattr(args, 'save_folder', f'results/HUST results/Experiment{e + 1}')
if not os.path.exists(args.save_folder):
os.makedirs(args.save_folder)
dataloader = load_HUST_data(args)
pinn = PINN(args)
pinn.Train(trainloader=dataloader['train'],validloader=dataloader['valid'],testloader=dataloader['test'])
def small_sample():
args = get_args()
for n in [1,2,3,4]:
for e in range(10):
setattr(args,'save_folder',f'results/HUST results (small sample {n})/Experiment{e+1}')
setattr(args,'batch_size',128)
if not os.path.exists(args.save_folder):
os.makedirs(args.save_folder)
dataloader = load_HUST_data(args,small_sample=n)
pinn = PINN(args)
pinn.Train(trainloader=dataloader['train'],validloader=dataloader['valid'],testloader=dataloader['test'])
if __name__ == '__main__':
pass
# main()
# small_sample()