1919- numpy: For numerical operations.
2020- bayesflow.approximators: Provides the `Approximator` class for extracting summary statistics.
2121- bayesflow.metrics: Provides the `maximum_mean_discrepancy` function for computing the MMD.
22-
23- Usage:
24- ------
25- These functions can be used to perform MMD hypothesis test by comparing observed data to reference data
26- or their respective summary statistics.
27-
28- Example:
29- --------
30- # Assuming `observed_data`, `reference_data`, and an `Approximator` instance are available:
31-
32- This results in namespace collision:
33- from bayesflow.diagnostics.metrics.mmd_hypothesis_test import mmd_hypothesis_test
34- from bayesflow.diagnostics.plots.mmd_hypothesis_test import mmd_hypothesis_test
35-
36- import bayesflow as bf
37-
38- # Perform the MMD hypothesis test
39- mmd_observed, mmd_null = bf.diagnostics.metrics.mmd_hypothesis_test(observed_data, reference_data, approximator)
40-
41- # Plot the null distribution and observed MMD
42- bf.diagnostics.plots.mmd_hypothesis_test(mmd_null=mmd_null, mmd_observed=mmd_observed)
4322"""
4423
4524import numpy as np
@@ -57,6 +36,25 @@ def compute_mmd_hypothesis_test_from_summaries(
5736 """Computes the Maximum Mean Discrepancy (MMD) between observed and reference summaries and generates a distribution
5837 of MMD values under the null hypothesis to assess model fit.
5938
39+ [1] M. Schmitt, P.-C. Bürkner, U. Köthe, and S. T. Radev, "Detecting model misspecification in amortized Bayesian
40+ inference with neural networks," arXiv e-prints, Dec. 2021, Art. no. arXiv:2112.08866.
41+ URL: https://arxiv.org/abs/2112.08866
42+
43+
44+ Example:
45+ --------
46+ # Assuming `observed_summaries` and `reference_summaries` are available:
47+
48+ from bayesflow.diagnostics.metrics import compute_mmd_hypothesis_test_from_summaries
49+ from bayesflow.diagnostics.plots import mmd_hypothesis_test
50+
51+ # Compute MMD values for hypothesis test
52+ mmd_observed, mmd_null = compute_mmd_hypothesis_test_from_summaries(observed_summaries, reference_summaries)
53+
54+ # Plot the null distribution and observed MMD
55+ fig = mmd_hypothesis_test(mmd_null=mmd_null, mmd_observed=mmd_observed)
56+
57+
6058 Parameters
6159 ----------
6260 observed_summary : np.ndarray
@@ -99,6 +97,25 @@ def compute_mmd_hypothesis_test(
9997 """Computes the Maximum Mean Discrepancy (MMD) between observed and reference data and generates a distribution of
10098 MMD values under the null hypothesis to assess model fit.
10199
100+ [1] M. Schmitt, P.-C. Bürkner, U. Köthe, and S. T. Radev, "Detecting model misspecification in amortized Bayesian
101+ inference with neural networks," arXiv e-prints, Dec. 2021, Art. no. arXiv:2112.08866.
102+ URL: https://arxiv.org/abs/2112.08866
103+
104+
105+ Example:
106+ --------
107+ # Assuming `observed_data`, `reference_data`, and an `Approximator` instance are available:
108+
109+ from bayesflow.diagnostics.metrics import compute_mmd_hypothesis_test
110+ from bayesflow.diagnostics.plots import mmd_hypothesis_test
111+
112+ # Compute MMD values for hypothesis test
113+ mmd_observed, mmd_null = compute_mmd_hypothesis_test(observed_data, reference_data, approximator)
114+
115+ # Plot the null distribution and observed MMD
116+ fig = mmd_hypothesis_test(mmd_null=mmd_null, mmd_observed=mmd_observed)
117+
118+
102119 Parameters
103120 ----------
104121 observed_data : np.ndarray
0 commit comments