-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathperformance_analysis.py
More file actions
93 lines (79 loc) · 3.19 KB
/
performance_analysis.py
File metadata and controls
93 lines (79 loc) · 3.19 KB
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
import sys
import numpy as np
from plasma.utils.performance import PerformanceAnalyzer
from plasma.conf import conf
# mode = 'test'
file_num = 0
save_figure = True
pred_ttd = False
T_min_warn = 30 # None #take value from conf #30
verbose = False
if len(sys.argv) > 1:
results_dir = sys.argv[1]
else:
results_dir = conf['paths']['results_prepath']
shots_dir = conf['paths']['processed_prepath']
analyzer = PerformanceAnalyzer(
conf=conf,
results_dir=results_dir,
shots_dir=shots_dir,
i=file_num,
T_min_warn=T_min_warn,
verbose=verbose,
pred_ttd=pred_ttd)
analyzer.load_ith_file()
P_thresh_opt = analyzer.compute_tradeoffs_and_print_from_training()
# P_thresh_opt = 0.566 # 0.566 # 0.92
# analyzer.compute_tradeoffs_and_print_from_training()
linestyle = "-"
P_thresh_range, missed_range, fp_range = analyzer.compute_tradeoffs_and_plot(
'test', save_figure=save_figure, plot_string='_test', linestyle=linestyle)
np.savez(
'test_roc.npz',
"P_thresh_range",
P_thresh_range,
"missed_range",
missed_range,
"fp_range",
fp_range)
analyzer.compute_tradeoffs_and_plot(
'train',
save_figure=save_figure,
plot_string='_train',
linestyle=linestyle)
analyzer.summarize_shot_prediction_stats_by_mode(P_thresh_opt, 'test')
normalize = True
analyzer.example_plots(P_thresh_opt, 'test', 'any', normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'test', ['FP'], extra_filename='test',
normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'test', ['FN'], extra_filename='test',
normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'test', ['TP'], extra_filename='test',
normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'test', ['late'], extra_filename='test',
normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'train', ['TN'], extra_filename='train',
normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'train', ['FP'], extra_filename='train',
normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'train', ['FN'], extra_filename='train',
normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'train', ['TP'], extra_filename='train',
normalize=normalize)
analyzer.example_plots(P_thresh_opt, 'train', ['late'], extra_filename='train',
normalize=normalize)
alarms, disr_alarms, nondisr_alarms = analyzer.gather_first_alarms(
P_thresh_opt, 'test')
analyzer.hist_alarms(disr_alarms, 'disruptive alarms, P thresh = {}'.format(
P_thresh_opt), save_figure=save_figure, linestyle=linestyle)
np.savez('disruptive_alarms_test.npz', "disr_alarms", disr_alarms,
"P_thresh_opt", P_thresh_opt)
print('{} disruptive alarms'.format(len(disr_alarms)))
print('{} seconds mean alarm time'.format(
np.mean(disr_alarms[disr_alarms > 0])))
print('{} seconds median alarm time'.format(
np.median(disr_alarms[disr_alarms > 0])))
analyzer.hist_alarms(nondisr_alarms,
'nondisruptive alarms, P thresh = {}'.format(P_thresh_opt)
)
print('{} nondisruptive alarms'.format(len(nondisr_alarms)))