@@ -246,7 +246,23 @@ def regularize_term(model, prior_FIM, theta_ref):
246
246
247
247
Added to SSE objective function
248
248
"""
249
- expr = ((theta - theta_ref ).transpose () * prior_FIM * (theta - theta_ref ) for theta in model .unknown_parameters .items ())
249
+ # Check if prior_FIM is a square matrix
250
+ if prior_FIM .shape [0 ] != prior_FIM .shape [1 ]:
251
+ raise ValueError ("prior_FIM must be a square matrix" )
252
+
253
+ # Check if theta_ref is a vector of the same size as prior_FIM
254
+ if len (theta_ref ) != prior_FIM .shape [0 ]:
255
+ raise ValueError ("theta_ref must be a vector of the same size as prior_FIM" )
256
+
257
+ # (theta - theta_ref).transpose() * prior_FIM * (theta - theta_ref)
258
+ expr = np .zeros (len (theta_ref ))
259
+
260
+ for i in range (len (theta_ref )):
261
+ if theta_ref [i ] is None :
262
+ raise ValueError ("theta_ref must not contain None values" )
263
+ expr [i ] = (model .unknown_parameters [i ] - theta_ref [i ]).transpose () * prior_FIM [i ] * (model .unknown_parameters [i ] - theta_ref [i ])
264
+ return sum (expr )** 2
265
+
250
266
return expr
251
267
252
268
@@ -449,10 +465,10 @@ def _create_parmest_model(self, experiment_number):
449
465
450
466
if self .prior_FIM and self .theta_ref is not None :
451
467
# Regularize the objective function
452
- second_stage_rule = SSE + regularize_term (prior_FIM = self .prior_FIM , theta_ref = self .theta_ref )
468
+ second_stage_rule = SSE + regularize_term (model = self . model_initialized , prior_FIM = self .prior_FIM , theta_ref = self .theta_ref )
453
469
elif self .prior_FIM :
454
470
theta_ref = model .unknown_parameters .values ()
455
- second_stage_rule = SSE + regularize_term (prior_FIM = self .prior_FIM , theta_ref = self . theta_ref )
471
+ second_stage_rule = SSE + regularize_term (prior_FIM = self .prior_FIM , theta_ref = theta_ref )
456
472
457
473
else :
458
474
# Sum of squared errors
0 commit comments