@@ -215,9 +215,11 @@ def get_numerical_second_derivative(grey_box_object=None, return_reduced=True):
215
215
for i in ordered_quads :
216
216
row = ordered_pairs_list .index (i [0 ])
217
217
col = ordered_pairs_list .index (i [1 ])
218
- numerical_derivative_reduced [row , col ] = numerical_derivative [
219
- i [0 ][0 ], i [0 ][1 ], i [1 ][0 ], i [1 ][1 ]
220
- ]
218
+ i , j , k , l = i [0 ][0 ], i [0 ][1 ], i [1 ][0 ], i [1 ][1 ]
219
+ multiplier = 1 + ((i != j ) + (k != l )) + ((i != j ) and (k != l )) * (i != k )
220
+ numerical_derivative_reduced [row , col ] = (
221
+ multiplier * numerical_derivative [i , j , k , l ]
222
+ )
221
223
222
224
numerical_derivative_reduced += (
223
225
numerical_derivative_reduced .transpose ()
@@ -524,7 +526,8 @@ def test_jacobian_A_opt(self):
524
526
# Recover the Jacobian in Matrix Form
525
527
jac = np .zeros_like (grey_box_object ._get_FIM ())
526
528
jac [np .triu_indices_from (jac )] = utri_vals_jac
527
- jac += jac .transpose () - np .diag (np .diag (jac ))
529
+ jac += jac .transpose ()
530
+ jac = jac / 2
528
531
529
532
# Get numerical derivative matrix
530
533
jac_FD = get_numerical_derivative (grey_box_object )
@@ -547,7 +550,8 @@ def test_jacobian_D_opt(self):
547
550
# Recover the Jacobian in Matrix Form
548
551
jac = np .zeros_like (grey_box_object ._get_FIM ())
549
552
jac [np .triu_indices_from (jac )] = utri_vals_jac
550
- jac += jac .transpose () - np .diag (np .diag (jac ))
553
+ jac += jac .transpose ()
554
+ jac = jac / 2
551
555
552
556
# Get numerical derivative matrix
553
557
jac_FD = get_numerical_derivative (grey_box_object )
@@ -570,7 +574,8 @@ def test_jacobian_E_opt(self):
570
574
# Recover the Jacobian in Matrix Form
571
575
jac = np .zeros_like (grey_box_object ._get_FIM ())
572
576
jac [np .triu_indices_from (jac )] = utri_vals_jac
573
- jac += jac .transpose () - np .diag (np .diag (jac ))
577
+ jac += jac .transpose ()
578
+ jac = jac / 2
574
579
575
580
# Get numerical derivative matrix
576
581
jac_FD = get_numerical_derivative (grey_box_object )
@@ -593,7 +598,8 @@ def test_jacobian_ME_opt(self):
593
598
# Recover the Jacobian in Matrix Form
594
599
jac = np .zeros_like (grey_box_object ._get_FIM ())
595
600
jac [np .triu_indices_from (jac )] = utri_vals_jac
596
- jac += jac .transpose () - np .diag (np .diag (jac ))
601
+ jac += jac .transpose ()
602
+ jac = jac / 2
597
603
598
604
# Get numerical derivative matrix
599
605
jac_FD = get_numerical_derivative (grey_box_object )
@@ -990,7 +996,10 @@ def test_solve_D_optimality_log_determinant(self):
990
996
# (time, optimal objective value)
991
997
# Here, the objective value is
992
998
# log-10(determinant) of the FIM
993
- optimal_experimental_designs = [np .array ([2.24 , 4.33 ]), np .array ([10.00 , 4.35 ])]
999
+ optimal_experimental_designs = [
1000
+ np .array ([1.782 , 4.34 ]),
1001
+ np .array ([10.00 , 4.35 ]),
1002
+ ]
994
1003
objective_option = "determinant"
995
1004
doe_object , grey_box_object = make_greybox_and_doe_objects_rooney_biegler (
996
1005
objective_option = objective_option
@@ -1002,12 +1011,6 @@ def test_solve_D_optimality_log_determinant(self):
1002
1011
# Solve the model
1003
1012
doe_object .run_doe ()
1004
1013
1005
- print ("Termination Message" )
1006
- print (doe_object .results ["Termination Message" ])
1007
- print (cyipopt_call_working )
1008
- print (bad_message in doe_object .results ["Termination Message" ])
1009
- print ("End Message" )
1010
-
1011
1014
optimal_time_val = doe_object .results ["Experiment Design" ][0 ]
1012
1015
optimal_obj_val = np .log10 (np .exp (pyo .value (doe_object .model .objective )))
1013
1016
@@ -1035,7 +1038,7 @@ def test_solve_A_optimality_trace_of_inverse(self):
1035
1038
# Here, the objective value is
1036
1039
# trace(inverse(FIM))
1037
1040
optimal_experimental_designs = [
1038
- np .array ([1.94 , 0.0295 ]),
1041
+ np .array ([1.33 , 0.0277 ]),
1039
1042
np .array ([9.9 , 0.0366 ]),
1040
1043
]
1041
1044
objective_option = "trace"
@@ -1076,7 +1079,7 @@ def test_solve_E_optimality_minimum_eigenvalue(self):
1076
1079
# Here, the objective value is
1077
1080
# minimum eigenvalue of the FIM
1078
1081
optimal_experimental_designs = [
1079
- np .array ([1.92 , 36.018 ]),
1082
+ np .array ([1.30 , 38.70 ]),
1080
1083
np .array ([10.00 , 28.349 ]),
1081
1084
]
1082
1085
objective_option = "minimum_eigenvalue"
@@ -1117,7 +1120,7 @@ def test_solve_ME_optimality_condition_number(self):
1117
1120
# Here, the objective value is
1118
1121
# condition number of the FIM
1119
1122
optimal_experimental_designs = [
1120
- np .array ([1.59 , 15.22 ]),
1123
+ np .array ([0.943 , 13.524 ]),
1121
1124
np .array ([10.00 , 27.675 ]),
1122
1125
]
1123
1126
objective_option = "condition_number"
0 commit comments