44import pytest
55
66
7- def test__zeroth_regularization_matrix_from ():
7+ def test__zeroth_regularization_matrix_from__coefficient_1_pixels_3__identity_diagonal_matrix ():
88 regularization_matrix = aa .util .regularization .zeroth_regularization_matrix_from (
99 coefficient = 1.0 , pixels = 3
1010 )
@@ -15,6 +15,8 @@ def test__zeroth_regularization_matrix_from():
1515 ).all ()
1616 assert abs (np .linalg .det (regularization_matrix )) > 1e-8
1717
18+
19+ def test__zeroth_regularization_matrix_from__coefficient_2_pixels_2__scaled_identity_matrix ():
1820 regularization_matrix = aa .util .regularization .zeroth_regularization_matrix_from (
1921 coefficient = 2.0 , pixels = 2
2022 )
@@ -23,13 +25,7 @@ def test__zeroth_regularization_matrix_from():
2325 assert abs (np .linalg .det (regularization_matrix )) > 1e-8
2426
2527
26- def test__constant_regularization_matrix_from ():
27- # Here, we define the neighbors first here and make the B matrices based on them.
28-
29- # You'll notice that actually, the B Matrix doesn't have to have the -1's going down the diagonal and we
30- # don't have to have as many B matrices as we do the pix pixel with the most vertices. We can combine
31- # the rows of each B matrix wherever we like ;0.
32-
28+ def test__constant_regularization_matrix_from__3_pixel_chain__matches_b_matrix_computation ():
3329 neighbors = np .array ([[1 , 2 , - 1 ], [0 , - 1 , - 1 ], [0 , - 1 , - 1 ]])
3430
3531 neighbors_sizes = np .array ([2 , 1 , 1 ])
@@ -47,6 +43,8 @@ def test__constant_regularization_matrix_from():
4743 assert (regularization_matrix == test_regularization_matrix ).all ()
4844 assert abs (np .linalg .det (regularization_matrix )) > 1e-8
4945
46+
47+ def test__constant_regularization_matrix_from__4_pixel_ring_coefficient_1__matches_b_matrix_computation ():
5048 b_matrix = np .array ([[- 1 , 1 , 0 , 0 ], [0 , - 1 , 1 , 0 ], [0 , 0 , - 1 , 1 ], [1 , 0 , 0 , - 1 ]])
5149
5250 test_regularization_matrix = np .matmul (b_matrix .T , b_matrix ) + 1e-8 * np .identity (4 )
@@ -64,6 +62,8 @@ def test__constant_regularization_matrix_from():
6462 assert (regularization_matrix == test_regularization_matrix ).all ()
6563 assert abs (np .linalg .det (regularization_matrix )) > 1e-8
6664
65+
66+ def test__constant_regularization_matrix_from__4_pixel_ring_coefficient_2__scaled_regularization_matrix ():
6767 neighbors = np .array (
6868 [[1 , 3 , - 1 , - 1 ], [0 , 2 , - 1 , - 1 ], [1 , 3 , - 1 , - 1 ], [0 , 2 , - 1 , - 1 ]]
6969 )
@@ -83,6 +83,8 @@ def test__constant_regularization_matrix_from():
8383 assert (regularization_matrix == test_regularization_matrix ).all ()
8484 assert abs (np .linalg .det (regularization_matrix )) > 1e-8
8585
86+
87+ def test__constant_regularization_matrix_from__9_pixel_grid__matches_b_matrix_computation ():
8688 neighbors = np .array (
8789 [
8890 [1 , 3 , - 1 , - 1 ],
@@ -164,7 +166,7 @@ def test__constant_zeroth_regularization_matrix_from():
164166 assert abs (np .linalg .det (regularization_matrix )) > 1e-8
165167
166168
167- def test__adapt_regularization_weights_from ():
169+ def test__adapt_regularization_weights_from__uniform_signals_equal_inner_outer__all_weights_one ():
168170 pixel_signals = np .array ([1.0 , 1.0 , 1.0 ])
169171
170172 weight_list = aa .util .regularization .adapt_regularization_weights_from (
@@ -173,6 +175,8 @@ def test__adapt_regularization_weights_from():
173175
174176 assert (weight_list == np .array ([1.0 , 1.0 , 1.0 ])).all ()
175177
178+
179+ def test__adapt_regularization_weights_from__non_uniform_signals_equal_inner_outer__all_weights_one ():
176180 pixel_signals = np .array ([0.25 , 0.5 , 0.75 ])
177181
178182 weight_list = aa .util .regularization .adapt_regularization_weights_from (
@@ -181,6 +185,8 @@ def test__adapt_regularization_weights_from():
181185
182186 assert (weight_list == np .array ([1.0 , 1.0 , 1.0 ])).all ()
183187
188+
189+ def test__adapt_regularization_weights_from__non_uniform_signals_outer_zero__weights_scale_with_signal ():
184190 pixel_signals = np .array ([0.25 , 0.5 , 0.75 ])
185191
186192 weight_list = aa .util .regularization .adapt_regularization_weights_from (
@@ -189,6 +195,8 @@ def test__adapt_regularization_weights_from():
189195
190196 assert (weight_list == np .array ([0.25 ** 2.0 , 0.5 ** 2.0 , 0.75 ** 2.0 ])).all ()
191197
198+
199+ def test__adapt_regularization_weights_from__non_uniform_signals_inner_zero__weights_scale_inversely ():
192200 pixel_signals = np .array ([0.25 , 0.5 , 0.75 ])
193201
194202 weight_list = aa .util .regularization .adapt_regularization_weights_from (
@@ -198,7 +206,7 @@ def test__adapt_regularization_weights_from():
198206 assert (weight_list == np .array ([0.75 ** 2.0 , 0.5 ** 2.0 , 0.25 ** 2.0 ])).all ()
199207
200208
201- def test__brightness_zeroth_regularization_weights_from ():
209+ def test__brightness_zeroth_regularization_weights_from__uniform_max_signals__all_zero_weights ():
202210 pixel_signals = np .array ([1.0 , 1.0 , 1.0 ])
203211
204212 weight_list = aa .util .regularization .brightness_zeroth_regularization_weights_from (
@@ -207,6 +215,8 @@ def test__brightness_zeroth_regularization_weights_from():
207215
208216 assert (weight_list == np .array ([0.0 , 0.0 , 0.0 ])).all ()
209217
218+
219+ def test__brightness_zeroth_regularization_weights_from__non_uniform_signals_coefficient_1__complement_weights ():
210220 pixel_signals = np .array ([0.25 , 0.5 , 0.75 ])
211221
212222 weight_list = aa .util .regularization .brightness_zeroth_regularization_weights_from (
@@ -215,6 +225,8 @@ def test__brightness_zeroth_regularization_weights_from():
215225
216226 assert (weight_list == np .array ([0.75 , 0.5 , 0.25 ])).all ()
217227
228+
229+ def test__brightness_zeroth_regularization_weights_from__non_uniform_signals_coefficient_2__scaled_complement_weights ():
218230 pixel_signals = np .array ([0.25 , 0.5 , 0.75 ])
219231
220232 weight_list = aa .util .regularization .brightness_zeroth_regularization_weights_from (
@@ -224,7 +236,7 @@ def test__brightness_zeroth_regularization_weights_from():
224236 assert (weight_list == np .array ([1.5 , 1.0 , 0.5 ])).all ()
225237
226238
227- def test__weighted_regularization_matrix_from ():
239+ def test__weighted_regularization_matrix_from__4_pixel_cycle_uniform_weights__matches_b_matrix ():
228240 neighbors = np .array ([[2 ], [3 ], [0 ], [1 ]])
229241
230242 b_matrix = np .array ([[- 1 , 0 , 1 , 0 ], [0 , - 1 , 0 , 1 ], [1 , 0 , - 1 , 0 ], [0 , 1 , 0 , - 1 ]])
@@ -240,6 +252,8 @@ def test__weighted_regularization_matrix_from():
240252
241253 assert regularization_matrix == pytest .approx (test_regularization_matrix , 1.0e-4 )
242254
255+
256+ def test__weighted_regularization_matrix_from__3_pixel_chain_uniform_weights__matches_b_matrix ():
243257 # Here, we define the neighbors first here and make the B matrices based on them.
244258
245259 # You'll notice that actually, the B Matrix doesn't have to have the -1's going down the diagonal and we
@@ -271,6 +285,8 @@ def test__weighted_regularization_matrix_from():
271285
272286 assert regularization_matrix == pytest .approx (test_regularization_matrix , 1.0e-4 )
273287
288+
289+ def test__weighted_regularization_matrix_from__4_pixel_ring_uniform_weights__matches_combined_b_matrix ():
274290 b_matrix_1 = np .array ([[- 1 , 1 , 0 , 0 ], [0 , - 1 , 1 , 0 ], [0 , 0 , - 1 , 1 ], [1 , 0 , 0 , - 1 ]])
275291
276292 test_regularization_matrix_1 = np .matmul (b_matrix_1 .T , b_matrix_1 )
@@ -294,6 +310,8 @@ def test__weighted_regularization_matrix_from():
294310
295311 assert regularization_matrix == pytest .approx (test_regularization_matrix , 1.0e-4 )
296312
313+
314+ def test__weighted_regularization_matrix_from__6_pixel_graph_uniform_weights__matches_b_matrix ():
297315 # Again, lets exploit the freedom we have when setting up our B matrices to make matching it to pairs a
298316 # lot less Stressful.
299317
@@ -378,6 +396,8 @@ def test__weighted_regularization_matrix_from():
378396
379397 assert regularization_matrix == pytest .approx (test_regularization_matrix , 1.0e-4 )
380398
399+
400+ def test__weighted_regularization_matrix_from__4_pixel_non_uniform_weights__matches_weighted_b_matrix ():
381401 # Simple case, where we have just one regularization direction, regularizing pixel 0 -> 1 and 1 -> 2.
382402
383403 # This means our B matrix is:
@@ -412,6 +432,8 @@ def test__weighted_regularization_matrix_from():
412432
413433 assert regularization_matrix == pytest .approx (test_regularization_matrix , 1.0e-4 )
414434
435+
436+ def test__weighted_regularization_matrix_from__6_pixel_non_uniform_weights__matches_weighted_b_matrix ():
415437 neighbors = np .array (
416438 [
417439 [1 , 4 , - 1 , - 1 ],
@@ -494,7 +516,7 @@ def test__weighted_regularization_matrix_from():
494516 assert regularization_matrix == pytest .approx (test_regularization_matrix , 1.0e-4 )
495517
496518
497- def test__brightness_zeroth_regularization_matrix_from ():
519+ def test__brightness_zeroth_regularization_matrix_from__uniform_weights__identity_diagonal_matrix ():
498520 regularization_weights = np .ones (shape = (3 ,))
499521
500522 regularization_matrix = (
@@ -507,6 +529,8 @@ def test__brightness_zeroth_regularization_matrix_from():
507529 np .array ([[1.0 , 0.0 , 0.0 ], [0.0 , 1.0 , 0.0 ], [0.0 , 0.0 , 1.0 ]]), 1.0e-4
508530 )
509531
532+
533+ def test__brightness_zeroth_regularization_matrix_from__non_uniform_weights__squared_weights_on_diagonal ():
510534 regularization_weights = np .array ([1.0 , 2.0 , 3.0 ])
511535
512536 regularization_matrix = (
@@ -578,7 +602,7 @@ def splitted_data():
578602 return splitted_mappings , splitted_sizes , splitted_weights
579603
580604
581- def test__reg_split_from (splitted_data ):
605+ def test__reg_split_from__splitted_mapping_data__produces_correct_mappings_sizes_and_weights (splitted_data ):
582606
583607 splitted_mappings , splitted_sizes , splitted_weights = splitted_data
584608
@@ -649,7 +673,7 @@ def test__reg_split_from(splitted_data):
649673 assert splitted_weights == pytest .approx (expected_weights , abs = 1.0e-4 )
650674
651675
652- def test__constant_pixel_splitted_regularization_matrix (splitted_data ):
676+ def test__pixel_splitted_regularization_matrix_from__uniform_weights__correct_regularization_matrix (splitted_data ):
653677
654678 splitted_mappings , splitted_sizes , splitted_weights = splitted_data
655679
@@ -676,6 +700,11 @@ def test__constant_pixel_splitted_regularization_matrix(splitted_data):
676700
677701 assert pytest .approx (regularization_matrix , 1e-4 ) == np .array (expected_reg_matrix )
678702
703+
704+ def test__pixel_splitted_regularization_matrix_from__non_uniform_weights__correct_regularization_matrix (splitted_data ):
705+
706+ splitted_mappings , splitted_sizes , splitted_weights = splitted_data
707+
679708 regularization_weights = np .array ([2.0 , 4.0 , 2.0 , 2.0 , 2.0 ])
680709
681710 regularization_matrix = (
0 commit comments