-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelicitation.py
97 lines (68 loc) · 2.86 KB
/
elicitation.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
from functions import *
import yaml
with open('config.yaml', 'r') as file:
cfg = yaml.safe_load(file)
import pdb
def parameter_elicitation_utilities_tanh(PE_info, PE_cost, rho_comfort):
best_info = 1 # 0.601
worst_info = 0 # 0.042
best_cost = 0 #12.14
worst_cost = 8131.71 #1000
w_best = tanh_fun(best_info, rho_comfort)
w_worst = tanh_fun(worst_info, rho_comfort)
w_PE = tanh_fun(PE_info, rho_comfort)
v_best = ((8131.71 - best_cost) / 8131.71) * w_best
v_worst = ((8131.71 - worst_cost) / 8131.71) * w_worst
v_PE = ((8131.71 - PE_cost) / 8131.71) * w_PE
print("Searching for a solution of the system of equations...")
num_points = 1000
# Generate a list of tuples with random initial points
init_list = [tuple(np.random.uniform(1, 1, 3)) for _ in range(num_points)]
params = None
for init in init_list:
try:
params = system_of_eq(y = v_PE, p = cfg["PE_prob"] , init = init, min_value = v_worst, max_value = v_best)
except:
continue
if params is None:
print("No solution found...")
return None
return params
def parameter_elicitation_utilities_linear(net, PE, PE_info, PE_cost, rho_comfort, value_function, logging = None):
net.update_beliefs()
# pdb.set_trace()
worst_info = min(net.get_node_value("INFO")) # 0 # 0.042
# net.set_evidence("Results_of_Colonoscopy", "colon_pred_true")
# net.update_beliefs()
best_info = max(net.get_node_value("INFO")) # 1 # 0.601
best_cost = 0 # 0 #12.14
worst_cost = 8131.71 #8131.71
v_best = rho_comfort * best_info - np.log10(best_cost+1)
v_worst = rho_comfort * worst_info - np.log10(worst_cost+1)
v_PE = rho_comfort * PE_info - np.log10(PE_cost+1)
if logging is not None:
logging.info(f"Best info: {best_info}")
logging.info(f"Worst info: {worst_info}")
logging.info(f"PE info: {PE_info}")
logging.info(f"v_best: {v_best}")
logging.info(f"v_worst: {v_worst}")
logging.info(f"v_PE: {v_PE}")
logging.info("Searching for a solution of the system of equations...")
num_points = 500
# Generate a list of tuples with random initial points
if value_function == "point_cond_mut_info":
init_list = [tuple(np.random.uniform(-0.01, 0.01, 3)) for _ in range(num_points)]
elif value_function == "rel_point_cond_mut_info":
init_list = [tuple(np.random.uniform(-1, 1, 3)) for _ in range(num_points)]
params = None
for init in init_list:
try:
params = system_of_eq(y = v_PE, p = PE , init = init, min_value = v_worst, max_value = v_best)
break
except:
continue
if params is None:
if logging is not None:
logging.warning("No solution found...")
return None
return params