Skip to content

Commit a34f4d9

Browse files
committed
Move tests and improve automatic documentation generation
1 parent 34ca72d commit a34f4d9

File tree

4 files changed

+62
-51
lines changed

4 files changed

+62
-51
lines changed

docs/conf.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
# for example take major/minor
3333
version = ".".join(release.split(".")[:2])
3434
except Exception:
35-
print("Warning: Could not determine version from package, using development version")
35+
print(
36+
"Warning: Could not determine version from package, using development version"
37+
)
3638
release = "0.0.0.dev"
3739
version = "0.0"
3840

@@ -61,7 +63,14 @@
6163
# sphinx-mdinclude will handle markdown parsing
6264

6365
# Mock imports
64-
autodoc_mock_imports = ["numpy", "matplotlib", "matplotlib.pyplot", "scipy", "neo", "numba"]
66+
autodoc_mock_imports = [
67+
"numpy",
68+
"matplotlib",
69+
"matplotlib.pyplot",
70+
"scipy",
71+
"neo",
72+
"numba",
73+
]
6574

6675
# Add any paths that contain templates here, relative to this directory.
6776
templates_path = ["_templates"]
@@ -217,5 +226,3 @@
217226

218227
# If true, `todo` and `todoList` produce output, else they produce nothing.
219228
todo_include_todos = True
220-
221-

docs/doc/contributing.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Contributing
2-
============
1+
32

43
.. mdinclude:: ../../CONTRIBUTING.md

tests/test_coefficients.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ def check_similarity_abs(value1, value2, max_difference=1e-10):
2121
return np.all(np.fabs(value1 - value2) < max_difference)
2222

2323

24-
25-
26-
2724
def calc_corr_arr_stationary(activity_mat, k_arr):
2825
average = np.mean(activity_mat)
2926
corr_arr = np.zeros_like(k_arr, dtype="float64")
@@ -84,8 +81,7 @@ def test_stationary_mean(self):
8481
activity_mat, steps=k_arr, method="stationarymean", numboot=numboot
8582
)
8683
print(
87-
f"stationarymean, time needed: "
88-
f"{(time.time() - time_beg) * 1000:.2f} ms"
84+
f"stationarymean, time needed: {(time.time() - time_beg) * 1000:.2f} ms"
8985
)
9086
print("mre: ", mre_res.coefficients[:5])
9187
print("true value: ", corr_arr[:5])
@@ -122,8 +118,7 @@ def test_separate(self):
122118
)
123119

124120
print(
125-
f"trialseparated, time needed: "
126-
f"{(time.time() - time_beg) * 1000:.2f} ms"
121+
f"trialseparated, time needed: {(time.time() - time_beg) * 1000:.2f} ms"
127122
)
128123
print("mre: ", mre_res.coefficients[:5])
129124
print("true value: ", corr_arr[:5])

tests/test_mr_estimator.py

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@ def calc_popt(
4848
if val < bound_min or val > bound_max:
4949
print(val)
5050
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")
5452
)
5553

5654
if not np.any(np.isfinite(corr_arr)):
@@ -127,18 +125,10 @@ def fitfunction_exp_with_offset(k_arr, tau, A, O):
127125

128126
def compare_mre_methods(activity_mat):
129127
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")
142132

143133
print("\n\n\n comparison:")
144134
print(rk1.coefficients[:10])
@@ -211,41 +201,51 @@ def test_stationary_mean(self):
211201
try_only_once=False,
212202
)
213203

214-
rk = mre.coefficients(activity_mat, method="stationarymean", steps=k_arr)
204+
rk = mre.coefficients(
205+
activity_mat, method="stationarymean", steps=k_arr
206+
)
215207
res_mre = mre.fit(rk, fitfunc="complex")
216208
print("popts:", popt, res_mre.popt)
217-
209+
218210
# Since the fits use different algorithms and starting points,
219211
# 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)
224219
extreme_manual = any(abs(val) > 1e6 for val in popt)
225220
extreme_mre = any(abs(val) > 1e6 for val in res_mre.popt)
226-
221+
227222
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+
)
229227
continue
230-
228+
231229
# For reasonable values, check similarity
232230
for i in range(len(popt)):
233231
manual_val = popt[i]
234232
mre_val = res_mre.popt[i]
235-
233+
236234
if abs(manual_val) < 1e-2 or abs(mre_val) < 1e-2:
237235
# For small values, use absolute difference
238236
self.assertTrue(
239237
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)",
241240
)
242241
else:
243242
# For larger values, use relative difference
244243
self.assertTrue(
245244
check_similarity(
246245
manual_val, mre_val, ratio_different=2e-1
247246
),
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)",
249249
)
250250
# plt.plot(k_arr, corr_arr)
251251
# plt.plot(k_arr, fitfunction_complex(k_arr, *popt))
@@ -265,39 +265,49 @@ def test_stationary_mean(self):
265265
# plt.plot(k_arr, corr_arr)
266266
# plt.plot(k_arr, fitfunction_exp_with_offset(k_arr, *popt))
267267
# 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+
)
269271
res_mre = mre.fit(rk, fitfunc="exponentialoffset")
270272
print("popts:", popt, res_mre.popt)
271273

272274
# Since the fits use different algorithms and starting points,
273275
# 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)
278283
extreme_manual = any(abs(val) > 1e6 for val in popt)
279284
extreme_mre = any(abs(val) > 1e6 for val in res_mre.popt)
280-
285+
281286
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+
)
283291
continue
284-
292+
285293
# For reasonable values, check similarity
286294
for i in range(len(popt)):
287295
manual_val = popt[i]
288296
mre_val = res_mre.popt[i]
289-
297+
290298
if abs(manual_val) < 1e-2 or abs(mre_val) < 1e-2:
291299
# For small values, use absolute difference
292300
self.assertTrue(
293301
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)",
295304
)
296305
else:
297306
# For larger values, use relative difference
298307
self.assertTrue(
299308
check_similarity(
300309
manual_val, mre_val, ratio_different=2e-1
301310
),
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)",
303313
)

0 commit comments

Comments
 (0)