numerical-validation

Detect and validate numerical accuracy in JAX-based scientific code after changes.

3|1|Updated Jun 7, 2023
One-click install
npx skills add https://github.com/LorenFrankLab/non_local_detector --skill numerical-validation
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: numerical-validation
Source: https://github.com/LorenFrankLab/non_local_detector/tree/main/.claude/skills/numerical-validation
Command: npx skills add https://github.com/LorenFrankLab/non_local_detector --skill numerical-validation

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires pytest, numpy, jax.

What problem does it solve?

Subtle numerical errors in scientific algorithms can lead to incorrect research conclusions, wasted effort, and unreliable software. This Skill provides a rigorous process to verify the mathematical correctness and numerical accuracy of your scientific code after any changes, ensuring the integrity of your results.

Core Features & Use Cases

  • Baseline Comparison: Capture and compare outputs before and after code changes to detect any numerical differences.
  • Mathematical Invariant Verification: Explicitly check critical properties like probabilities summing to one or matrices being stochastic.
  • Property-Based Testing: Use advanced testing techniques to verify invariants across a wide range of random inputs and edge cases.
  • Golden Regression Testing: Compare against validated reference outputs using real scientific data to catch subtle changes affecting scientific conclusions.
  • Use Case: After optimizing a JAX-based Hidden Markov Model (HMM) filter for performance, use this Skill to confirm that the faster code produces numerically identical results to the original, ensuring no accuracy was sacrificed for speed.

Quick Start

Follow the numerical validation checklist:

1. Capture baseline outputs before change

2. Make the code change

3. Capture new outputs after change

4. Compare numerical differences

5. Verify mathematical invariants

6. Run property-based tests

7. Run golden regression tests

8. Generate full analysis report

9. Present analysis and request approval (if differences found)

Frequently Asked Questions about numerical-validation

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I verify numerical accuracy after changes to scientific code?

Numerical validation captures baseline outputs before changes, then compares post-change results to detect numerical differences. This process ensures mathematical correctness in algorithms, HMM components, and JAX-based computations by checking if outputs remain within fixed tolerances—typically 1e-14 for refactoring or 1e-10 for algorithm modifications.

What mathematical invariants should I verify in scientific computing code?

Critical invariants include probabilities summing to one, transition matrices being stochastic, log-probabilities remaining finite, and covariance matrices being positive semi-definite. Validating these properties alongside numerical outputs prevents subtle logical errors in HMM filters, likelihood models, and state transitions that could compromise research conclusions.

Can I use property-based testing to catch edge cases in numerical computations?

Yes. Property-based testing verifies invariants across random inputs and edge cases automatically. Combined with golden regression testing against validated reference outputs on real scientific data, this technique catches subtle numerical changes that basic testing might miss in JAX and NumPy computations.

How do I compare numerical outputs before and after optimizing JAX code?

Baseline comparison captures output values before optimization, makes the code change, then compares new outputs against the baseline. The validation process reports numerical differences and generates analysis showing whether performance improvements introduced numerical drift or maintained accuracy within your specified tolerance.

What dependencies do I need for numerical validation testing?

Numerical validation requires pytest for test execution, NumPy for numerical operations, and JAX for advanced array computing on your scientific code. These dependencies enable baseline capture, invariant verification, property testing, and automated comparison of numerical outputs across code changes.

Why should I validate numerical code instead of relying on unit tests alone?

Unit tests verify logic but may miss subtle numerical errors that accumulate through algorithms, affecting research conclusions. Numerical validation adds rigorous baseline comparison, invariant checking, and regression testing specifically designed to detect accuracy loss in mathematical code—critical for scientific integrity.