@@ -35,6 +35,13 @@ def test_metric_calibration_error(random_estimates, random_targets, var_names):
3535 assert out ["values" ].shape == (random_estimates ["sigma" ].shape [- 1 ],)
3636 assert out ["variable_names" ] == ["sigma" ]
3737
38+ # test quantities
39+ test_quantities = {
40+ r"$\beta_1 + \beta_2$" : lambda data : np .sum (data ["beta" ], axis = - 1 ),
41+ r"$\beta_1 \cdot \beta_2$" : lambda data : np .prod (data ["beta" ], axis = - 1 ),
42+ }
43+ out = bf .diagnostics .metrics .calibration_error (random_estimates , random_targets , test_quantities = test_quantities )
44+ assert out ["values" ].shape [0 ] == len (test_quantities ) + num_variables (random_estimates )
3845
3946def test_posterior_contraction (random_estimates , random_targets ):
4047 # basic functionality: automatic variable names
@@ -47,6 +54,16 @@ def test_posterior_contraction(random_estimates, random_targets):
4754 out = bf .diagnostics .metrics .posterior_contraction (random_estimates , random_targets , aggregation = None )
4855 assert out ["values" ].shape == (random_estimates ["sigma" ].shape [0 ], num_variables (random_estimates ))
4956
57+ # test quantities
58+ test_quantities = {
59+ r"$\beta_1 + \beta_2$" : lambda data : np .sum (data ["beta" ], axis = - 1 ),
60+ r"$\beta_1 \cdot \beta_2$" : lambda data : np .prod (data ["beta" ], axis = - 1 ),
61+ }
62+ out = bf .diagnostics .metrics .posterior_contraction (
63+ random_estimates , random_targets , test_quantities = test_quantities
64+ )
65+ assert out ["values" ].shape [0 ] == len (test_quantities ) + num_variables (random_estimates )
66+
5067
5168def test_root_mean_squared_error (random_estimates , random_targets ):
5269 # basic functionality: automatic variable names
@@ -56,6 +73,16 @@ def test_root_mean_squared_error(random_estimates, random_targets):
5673 assert out ["metric_name" ] == "NRMSE"
5774 assert out ["variable_names" ] == ["beta_0" , "beta_1" , "sigma" ]
5875
76+ # test quantities
77+ test_quantities = {
78+ r"$\beta_1 + \beta_2$" : lambda data : np .sum (data ["beta" ], axis = - 1 ),
79+ r"$\beta_1 \cdot \beta_2$" : lambda data : np .prod (data ["beta" ], axis = - 1 ),
80+ }
81+ out = bf .diagnostics .metrics .root_mean_squared_error (
82+ random_estimates , random_targets , test_quantities = test_quantities
83+ )
84+ assert out ["values" ].shape [0 ] == len (test_quantities ) + num_variables (random_estimates )
85+
5986
6087def test_classifier_two_sample_test (random_samples_a , random_samples_b ):
6188 metric = bf .diagnostics .metrics .classifier_two_sample_test (estimates = random_samples_a , targets = random_samples_a )
@@ -95,6 +122,16 @@ def test_calibration_log_gamma(random_estimates, random_targets):
95122 assert out ["metric_name" ] == "Log Gamma"
96123 assert out ["variable_names" ] == ["beta_0" , "beta_1" , "sigma" ]
97124
125+ # test quantities
126+ test_quantities = {
127+ r"$\beta_1 + \beta_2$" : lambda data : np .sum (data ["beta" ], axis = - 1 ),
128+ r"$\beta_1 \cdot \beta_2$" : lambda data : np .prod (data ["beta" ], axis = - 1 ),
129+ }
130+ out = bf .diagnostics .metrics .calibration_log_gamma (
131+ random_estimates , random_targets , test_quantities = test_quantities
132+ )
133+ assert out ["values" ].shape [0 ] == len (test_quantities ) + num_variables (random_estimates )
134+
98135
99136def test_calibration_log_gamma_end_to_end ():
100137 # This is a function test for simulation-based calibration.
0 commit comments