Skip to content

Commit f180ab4

Browse files
committed
Support non-array data in test_quantity calibration ecdf [no ci]
Simulator outputs are allowed to be of type int or float, and consequently have no batch dimension. This needs to be considered in the broadcasting of inference_conditions for data based SBC test quantities. "examples/Linear_Regression_Starter.ipynb" contains an example where this is necessary, where N is a non-batchable integer.
1 parent 292419c commit f180ab4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

bayesflow/diagnostics/plots/calibration_ecdf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,10 @@ def calibration_ecdf(
147147
# Flatten estimates for batch processing in test_quantity_fn, apply function, and restore shape
148148
num_conditions, num_samples = next(iter(estimates.values())).shape[:2]
149149
flattened_estimates = keras.tree.map_structure(
150-
lambda t: np.reshape(t, (num_conditions * num_samples, *t.shape[2:])), estimates
150+
lambda t: np.reshape(t, (num_conditions * num_samples, *t.shape[2:]))
151+
if isinstance(t, np.ndarray)
152+
else t,
153+
estimates,
151154
)
152155
flat_tq_estimates = test_quantity_fn(data=flattened_estimates)
153156
test_quantities_estimates[key] = np.reshape(flat_tq_estimates, (num_conditions, num_samples, 1))

0 commit comments

Comments
 (0)