-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevent_model.py
executable file
·72 lines (56 loc) · 2.85 KB
/
event_model.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
#!/usr/bin/env python3
# Replace spaces by underscores to enable argcomplete "PYTHON ARGCOMPLETE OK"
from ROOT import PyConfig
PyConfig.IgnoreCommandLineOptions = 1 # This option has to bet set prior to importing argparse
import argparse
import pickle
import matplotlib.pyplot as plt
import lib
try:
import argcomplete
except ImportError:
pass
ParticleFrame = lib.ParticleFrame
# Assemble the allowed command line options
parser = argparse.ArgumentParser(description='Calculating and visualizing metrics.', formatter_class=argparse.ArgumentDefaultsHelpFormatter)
group_util = parser.add_argument_group('utility options', 'Parameters for altering the behavior of the program\'s input-output handling')
group_util.add_argument('--history-file', dest='history_path', action='store', default=None, required=True,
help='Path including the filename where the history of the model-fitting should be saved to; Skip saving if given \'/dev/null\'')
group_util.add_argument('-o', '--output', dest='output_directory', action='store', default='./res/',
help='Directory for the generated output (mainly plots); Skip saving plots if given \'/dev/null\'')
group_util.add_argument('--interactive', dest='interactive', action='store_true', default=True,
help='Run interactively, i.e. show plots')
group_util.add_argument('--non-interactive', dest='interactive', action='store_false', default=True,
help='Run non-interactively and hence unattended, i.e. show no plots')
try:
argcomplete.autocomplete(parser)
except NameError:
pass
args = parser.parse_args()
# Evaluate the input-output arguments
interactive = args.interactive
output_directory = args.output_directory
history_path = args.history_path
# Initialize an empty ParticleFrame and load the pickle_file
data = ParticleFrame(output_directory=output_directory, interactive=interactive)
history = pickle.load(open(history_path, 'rb'))
savefile_suffix = ' ' + history['savefile_suffix']
plt.figure()
for key, label in [('val_loss', 'Validation'), ('loss', 'Training')]:
plt.plot(history['epoch'], history['history'][key], label=label)
plt.xticks(fontsize='x-large')
plt.yticks(fontsize='x-large')
plt.xlabel('Epoch', fontsize='xx-large')
plt.ylabel('Loss', fontsize='xx-large')
plt.legend(fontsize='large')
data.pyplot_sanitize_show('Loss', savefig_prefix='Neural Network Model: ', savefig_suffix=savefile_suffix)
plt.figure()
for key, label in [('val_acc', 'Validation'), ('acc', 'Training')]:
plt.plot(history['epoch'], history['history'][key], label=label)
plt.xticks(fontsize='x-large')
plt.yticks(fontsize='x-large')
plt.xlabel('Epoch', fontsize='xx-large')
plt.ylabel('Accuracy', fontsize='xx-large')
plt.legend(fontsize='large')
data.pyplot_sanitize_show('Accuracy', savefig_prefix='Neural Network Model: ', savefig_suffix=savefile_suffix)
plt.show()