@@ -48,9 +48,7 @@ def calc_popt(
48
48
if val < bound_min or val > bound_max :
49
49
print (val )
50
50
raise (
51
- RuntimeError (
52
- f"startvalue { val } outside bounds, { i + 1 } -th value"
53
- )
51
+ RuntimeError (f"startvalue { val } outside bounds, { i + 1 } -th value" )
54
52
)
55
53
56
54
if not np .any (np .isfinite (corr_arr )):
@@ -127,18 +125,10 @@ def fitfunction_exp_with_offset(k_arr, tau, A, O):
127
125
128
126
def compare_mre_methods (activity_mat ):
129
127
print ("comparing mre internally:" )
130
- rk1 = mre .coefficients (
131
- activity_mat , steps = (1 , 1500 ), method = "trialseparated"
132
- )
133
- rk2 = mre .coefficients (
134
- activity_mat , steps = (1 , 1500 ), method = "trialseparated"
135
- )
136
- rk3 = mre .coefficients (
137
- activity_mat , steps = (1 , 1500 ), method = "stationarymean"
138
- )
139
- rk4 = mre .coefficients (
140
- activity_mat , steps = (1 , 1500 ), method = "stationarymean"
141
- )
128
+ rk1 = mre .coefficients (activity_mat , steps = (1 , 1500 ), method = "trialseparated" )
129
+ rk2 = mre .coefficients (activity_mat , steps = (1 , 1500 ), method = "trialseparated" )
130
+ rk3 = mre .coefficients (activity_mat , steps = (1 , 1500 ), method = "stationarymean" )
131
+ rk4 = mre .coefficients (activity_mat , steps = (1 , 1500 ), method = "stationarymean" )
142
132
143
133
print ("\n \n \n comparison:" )
144
134
print (rk1 .coefficients [:10 ])
@@ -211,41 +201,51 @@ def test_stationary_mean(self):
211
201
try_only_once = False ,
212
202
)
213
203
214
- rk = mre .coefficients (activity_mat , method = "stationarymean" , steps = k_arr )
204
+ rk = mre .coefficients (
205
+ activity_mat , method = "stationarymean" , steps = k_arr
206
+ )
215
207
res_mre = mre .fit (rk , fitfunc = "complex" )
216
208
print ("popts:" , popt , res_mre .popt )
217
-
209
+
218
210
# Since the fits use different algorithms and starting points,
219
211
# we should be more lenient with the comparison
220
- # Some datasets may converge to very different solutions due to numerical issues
221
- # Check if the fits look reasonable (not extreme values) before comparing
222
-
223
- # Skip comparison if either fit resulted in extreme values (likely convergence failure)
212
+ # Some datasets may converge to very different solutions due to
213
+ # numerical issues
214
+ # Check if the fits look reasonable (not extreme values) before
215
+ # comparing
216
+
217
+ # Skip comparison if either fit resulted in extreme values
218
+ # (likely convergence failure)
224
219
extreme_manual = any (abs (val ) > 1e6 for val in popt )
225
220
extreme_mre = any (abs (val ) > 1e6 for val in res_mre .popt )
226
-
221
+
227
222
if extreme_manual or extreme_mre :
228
- print (f"Skipping comparison for { name_data } due to extreme parameter values" )
223
+ print (
224
+ f"Skipping comparison for { name_data } due to "
225
+ "extreme parameter values"
226
+ )
229
227
continue
230
-
228
+
231
229
# For reasonable values, check similarity
232
230
for i in range (len (popt )):
233
231
manual_val = popt [i ]
234
232
mre_val = res_mre .popt [i ]
235
-
233
+
236
234
if abs (manual_val ) < 1e-2 or abs (mre_val ) < 1e-2 :
237
235
# For small values, use absolute difference
238
236
self .assertTrue (
239
237
abs (manual_val - mre_val ) < 1e-2 ,
240
- f"Parameter { i } : { manual_val } vs { mre_val } (absolute diff too large)"
238
+ f"Parameter { i } : { manual_val } vs { mre_val } "
239
+ "(absolute diff too large)" ,
241
240
)
242
241
else :
243
242
# For larger values, use relative difference
244
243
self .assertTrue (
245
244
check_similarity (
246
245
manual_val , mre_val , ratio_different = 2e-1
247
246
),
248
- f"Parameter { i } : { manual_val } vs { mre_val } (relative diff too large)"
247
+ f"Parameter { i } : { manual_val } vs { mre_val } "
248
+ "(relative diff too large)" ,
249
249
)
250
250
# plt.plot(k_arr, corr_arr)
251
251
# plt.plot(k_arr, fitfunction_complex(k_arr, *popt))
@@ -265,39 +265,49 @@ def test_stationary_mean(self):
265
265
# plt.plot(k_arr, corr_arr)
266
266
# plt.plot(k_arr, fitfunction_exp_with_offset(k_arr, *popt))
267
267
# plt.show()
268
- rk = mre .coefficients (activity_mat , method = "stationarymean" , steps = k_arr )
268
+ rk = mre .coefficients (
269
+ activity_mat , method = "stationarymean" , steps = k_arr
270
+ )
269
271
res_mre = mre .fit (rk , fitfunc = "exponentialoffset" )
270
272
print ("popts:" , popt , res_mre .popt )
271
273
272
274
# Since the fits use different algorithms and starting points,
273
275
# we should be more lenient with the comparison
274
- # Some datasets may converge to very different solutions due to numerical issues
275
- # Check if the fits look reasonable (not extreme values) before comparing
276
-
277
- # Skip comparison if either fit resulted in extreme values (likely convergence failure)
276
+ # Some datasets may converge to very different solutions due to
277
+ # numerical issues
278
+ # Check if the fits look reasonable (not extreme values) before
279
+ # comparing
280
+
281
+ # Skip comparison if either fit resulted in extreme values
282
+ # (likely convergence failure)
278
283
extreme_manual = any (abs (val ) > 1e6 for val in popt )
279
284
extreme_mre = any (abs (val ) > 1e6 for val in res_mre .popt )
280
-
285
+
281
286
if extreme_manual or extreme_mre :
282
- print (f"Skipping comparison for { name_data } due to extreme parameter values" )
287
+ print (
288
+ f"Skipping comparison for { name_data } due to "
289
+ "extreme parameter values"
290
+ )
283
291
continue
284
-
292
+
285
293
# For reasonable values, check similarity
286
294
for i in range (len (popt )):
287
295
manual_val = popt [i ]
288
296
mre_val = res_mre .popt [i ]
289
-
297
+
290
298
if abs (manual_val ) < 1e-2 or abs (mre_val ) < 1e-2 :
291
299
# For small values, use absolute difference
292
300
self .assertTrue (
293
301
abs (manual_val - mre_val ) < 1e-2 ,
294
- f"Parameter { i } : { manual_val } vs { mre_val } (absolute diff too large)"
302
+ f"Parameter { i } : { manual_val } vs { mre_val } "
303
+ "(absolute diff too large)" ,
295
304
)
296
305
else :
297
306
# For larger values, use relative difference
298
307
self .assertTrue (
299
308
check_similarity (
300
309
manual_val , mre_val , ratio_different = 2e-1
301
310
),
302
- f"Parameter { i } : { manual_val } vs { mre_val } (relative diff too large)"
311
+ f"Parameter { i } : { manual_val } vs { mre_val } "
312
+ "(relative diff too large)" ,
303
313
)
0 commit comments