Metamorphic Test Suite Script for Bayesian Inference Pipelines
Develop a metamorphic statistical test script to detect sampling drift, distribution collapse, and algorithmic bias.
Use this template when setting up automated regression and statistical validation tests for stochastic algorithms, MCMC samplers, and Bayesian models. It outputs a script utilizing two-sample statistical tests on metamorphic transformations.
Role: Lead Machine Learning QA Architect specializing in Probabilistic Systems and Statistical Inference.
Context
- Inference algorithm under test: {{inference_algorithm}}
- Metamorphic relations to test: {{metamorphic_relations}}
- Input distribution specification: {{input_distribution_spec}}
- Prior distribution rules: {{prior_distribution_rules}}
- Statistical significance threshold: {{drift_significance_level}}
- Target runtime platform: {{runtime_platform_runtime}}
Task
Author an end-to-end metamorphic testing and statistical assertion script in {{runtime_platform_runtime}} to detect algorithmic regression, numerical drift, and sampling distribution collapse in complex probabilistic models.
Method
- Parse the expected behavior of {{inference_algorithm}} alongside its baseline distribution constraints.
- Generate synthetic test datasets conforming to {{input_distribution_spec}} using deterministic pseudo-random seeds.
- Apply metamorphic transformations defined in {{metamorphic_relations}} (e.g., affine scaling, label permutations, coordinate shifts).
- Execute inference across base and transformed datasets, recording posterior parameter estimates.
- Implement two-sample statistical hypothesis tests (e.g., Kolmogorov-Smirnov, Wasserstein distance) calibrated to {{drift_significance_level}}.
- Validate that posterior outputs respect constraints from {{prior_distribution_rules}}.
- Implement failure diagnostics that output quantile-quantile comparisons and divergence metrics when tests reject the null hypothesis.
Constraints
- The script MUST be written as a self-contained, runnable test suite for {{runtime_platform_runtime}}.
- Statistical assertions MUST NOT use fixed threshold comparisons for stochastic outputs; two-sample statistical tests are required.
- Execution MUST emit standardized test output with significance p-values and effect sizes.
- Every metamorphic relation MUST have an explicit deterministic baseline and transformation function.
Output format
Provide a complete executable script containing:
- Dataset Synthesis and Metamorphic Transformation Helpers
- Probabilistic Oracle and Statistical Test Assertion Classes
- Parametrized Test Suite Execution Runner
- Divergence Metric Logging and Structured Report Exporter
Self-review
- Confirm {{inference_algorithm}} output distributions are validated using valid statistical hypothesis tests.
- Verify {{metamorphic_relations}} transformations preserve expected mathematical invariants.
- Ensure execution does not depend on non-deterministic unseeded random states.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.