-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmonitor.py
116 lines (76 loc) · 4.52 KB
/
monitor.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
import copy
import numpy as np
from scipy.optimize import curve_fit
import computation
import utils
def get_optimal_stopping_point(comprehensive_values):
return list(comprehensive_values).index(max(comprehensive_values))
def get_fixed_stopping_point(steps, profile_4, config):
best_values = []
for step in steps:
expected_value = 0
for target_class in config['solution_quality_classes']:
target_quality = utils.get_bin_value(target_class, config['solution_quality_class_count'])
intrinsic_value = computation.get_intrinsic_values(target_quality, config['intrinsic_value_multiplier'])
time_cost = computation.get_time_costs(step, config['time_cost_multiplier'])
comprehensive_value = computation.get_comprehensive_values(intrinsic_value, time_cost)
expected_value += profile_4[step][target_class] * comprehensive_value
best_values.append(expected_value)
return get_optimal_stopping_point(best_values)
def get_nonmyopic_stopping_point(qualities, steps, values, profile_2, profile_3, limit, config):
for step in steps:
if step + 1 == limit:
return step
action = computation.get_optimal_action(qualities[step], step, values, profile_2, profile_3, config)
if action is computation.STOP_SYMBOL:
return step
def get_myopic_stopping_point(qualities, steps, profile_1, profile_3, limit, config):
for step in steps:
if step + 1 == limit:
return step
mevc = computation.get_mevc(qualities[step], step, profile_1, profile_3, config)
if mevc <= 0:
return step
def get_nonmyopic_projected_stopping_point(qualities, steps, limit, config):
intrinsic_value_groups = []
stopping_point = 0
model = lambda x, a, b, c: a * np.arctan(x + b) + c
for end in range(config['monitor_threshold'], limit):
try:
start = 0 if config['window'] is None else end - config['window']
params, _ = curve_fit(model, steps[start:end], qualities[start:end])
projections = model(steps, params[0], params[1], params[2])
intrinsic_values = computation.get_intrinsic_values(projections, config['intrinsic_value_multiplier'])
time_costs = computation.get_time_costs(steps, config['time_cost_multiplier'])
comprehensive_values = computation.get_comprehensive_values(intrinsic_values, time_costs)
stopping_point = get_optimal_stopping_point(comprehensive_values)
intrinsic_value_groups.append(intrinsic_values)
if stopping_point < end - 1:
return end - 1, intrinsic_value_groups
except (RuntimeError, TypeError) as e:
pass
return stopping_point, intrinsic_value_groups
def get_myopic_projected_stopping_point(qualities, steps, limit, config):
intrinsic_value_groups = []
stopping_point = limit - 1
model = lambda x, a, b, c: a * np.arctan(x + b) + c
for end in range(config['monitor_threshold'], limit):
try:
start = 0 if config['window'] is None else end - config['window']
params, _ = curve_fit(model, steps[start:end], qualities[start:end])
projections = model(steps, params[0], params[1], params[2])
intrinsic_values = computation.get_intrinsic_values(projections, config['intrinsic_value_multiplier'])
time_costs = computation.get_time_costs(steps, config['time_cost_multiplier'])
comprehensive_values = computation.get_comprehensive_values(intrinsic_values, time_costs)
intrinsic_value_groups.append(intrinsic_values)
current_intrinsic_value = computation.get_intrinsic_values(qualities[end - 1], config['intrinsic_value_multiplier'])
current_time_cost = computation.get_time_costs(end - 1, config['time_cost_multiplier'])
current_comprehensive_value = computation.get_comprehensive_values(current_intrinsic_value, current_time_cost)
next_intrinsic_value = computation.get_intrinsic_values(projections[end], config['intrinsic_value_multiplier'])
next_time_cost = computation.get_time_costs(end, config['time_cost_multiplier'])
next_comprehensive_value = computation.get_comprehensive_values(next_intrinsic_value, next_time_cost)
if next_comprehensive_value - current_comprehensive_value <= 0:
return end - 1, intrinsic_value_groups
except (RuntimeError, TypeError) as e:
pass
return stopping_point, intrinsic_value_groups