-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
109 lines (99 loc) · 4.29 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
# Kenny Schlegel, Peer Neubert, Peter Protzel
#
# HDC-MiniROCKET : Explicit Time Encoding in Time Series Classification with Hyperdimensional Computing
# Copyright (C) 2022 Chair of Automation Technology / TU Chemnitz
from argparse import ArgumentParser
from datetime import datetime
import config
from main_run import *
import faulthandler
import os
from config import *
faulthandler.enable()
# config logger
import logging
logging.basicConfig(level=logging.INFO, format='%(message)s')
logging.root.setLevel(logging.INFO)
logger = logging.getLogger('log')
if not os.path.exists("./logs"):
os.makedirs("./logs")
logger.addHandler(logging.FileHandler('./logs/main_log.log', 'a'))
if __name__ == '__main__':
parser = ArgumentParser(description=__doc__)
parser.add_argument('--dataset', '-d',
help='Which dataset should be used?',
choices={'UCR','synthetic','synthetic_hard'},
default='UCR')
parser.add_argument('--dataset_path',
help='Path to dataset',
default='data')
parser.add_argument('--complete_UCR',
help='Run on all UCR univariate timeseries datasets',
action='store_true',
default=False)
parser.add_argument('--multi_scale',
help='Run on different scaling parameters (defined in config file)',
action='store_true',
default=False)
parser.add_argument('--normalize',
help='If dataset should be normalized',
action='store_true',
default=True)
parser.add_argument('--HDC_dim',
help='Defines the HDC dimension',
type=int,
default=9996)
parser.add_argument('--scale',
help='scaling of the scalar encoding with fractional binding ',
default=0)
parser.add_argument('--ensemble_idx',
help='index for UCR dataset ensemble',
type=int,
default=0)
parser.add_argument('--stat_iterations',
help='number of repetition for statistical evaluation',
default=1)
parser.add_argument('--config',
help='define the config struct in config.py for more parameters',
default='Config_orig')
parser.add_argument('--model',
help='Which model should be used?',
choices={'HDC_MINIROCKET','MINIROCKET'},
default='HDC_MINIROCKET')
args = parser.parse_args()
args.scale = float(args.scale)
# init high level network trainer
trainer = NetTrial(args)
logger.info('_________________________' + str(datetime.now()))
logger.info("--- " + args.model + " Model---")
logger.info("- Dataset: " + args.dataset)
logger.info("- Normalization: " + str(args.normalize))
logger.info("- Config: " + str(args.config))
if args.multi_scale:
exec('config = ' + args.config + '()')
logger.info("##### Run on multiple scales: " + str(config.scales))
scales = config.scales
else:
scales = np.array([args.scale])
for s_idx in range(len(scales)):
args.scale = scales[s_idx]
logger.info("Scale = " + str(args.scale))
if args.complete_UCR:
logger.info("##### Full experiment on all UCR univariate time series")
for i in range(128):
trainer = NetTrial(args)
logger.info("Index: " + str(i))
trainer.config.ensemble_idx = i
trainer.config.scale_idx = s_idx
trainer.load_data()
trainer.train()
del trainer
else:
logger.info("#### normal Training on " + args.dataset + ": ")
logger.info("Config: HDC_dim = " + str(args.HDC_dim) + " scale = " + str(args.scale))
logger.info("UCR Index = " + str(args.ensemble_idx))
trainer = NetTrial(args)
trainer.config.ensemble_idx = args.ensemble_idx
trainer.config.scale_idx = s_idx
trainer.load_data()
trainer.train()