Skip to content
Back to skills

Posterior Sample Approximation

ASecurity

Fit compact posterior approximations from SBI simulator pairs and emit posterior samples with optimizer traces.

  • 247 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 9, 2026
toolspythongobash

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned September 9, 2026

npx -y skills add VectorSpaceLab/AREX-Skill --skill posterior_sample_approximation --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Posterior Sample Approximation?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Posterior Sample Approximation
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/vectorspacelab-posterior-sample-approximation/badge)](https://www.skillsdirectory.com/skills/vectorspacelab-posterior-sample-approximation)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: posterior_sample_approximation
description: Fit compact posterior approximations from SBI simulator pairs and emit posterior samples with optimizer traces.
---

# Posterior Sample Approximation

Use this skill when an SBI recovery needs approximate posterior samples from simulation pairs and a fixed observation. It is designed for bounded reduced experiments where a full neural density estimator is unavailable, but the run must still perform an actual optimizer step and return posterior samples.

Do not use this skill as a substitute for a full neural SBI algorithm when that runtime is available. It is a reduced mechanism-preserving approximation.

## Inputs

- Simulation JSON with `theta` and `x` arrays.
- Conditioning observation vector.
- Training settings: learning rate, number of steps, seed.
- Posterior sampling settings: sample count and sample variance.

## Outputs

- Approximate posterior sample JSON.
- Training trace with before/after loss and before/after trainable parameters.

## Workflow

1. Load simulator pairs created by the task protocol skill.
2. Fit an affine map from observations to parameter means with gradient descent.
3. Record `loss_before`, `loss_after`, `params_before`, `params_after`, and `optimizer_state_changed`.
4. Condition the fitted map on the target observation.
5. Draw approximate posterior samples around the predicted mean.
6. Save the sample file and training trace for the recovery validator.

## Validation

Run:

```bash
python scripts/posterior_sample_approximation.py self-test
python tests/test_posterior_sample_approximation.py
```

## Limitations

This script implements a small affine posterior mean model with diagonal Gaussian sampling noise. It demonstrates the benchmark mechanism and optimizer evidence, but it is not a normalizing-flow posterior estimator.

The `optimizer_state_changed` flag is evidence-bearing: a zero-step or otherwise frozen run must leave it `false`, with identical `params_before` and `params_after`.

Files in this skill

  • SKILL.md2 KB
  • scripts/posterior_sample_approximation.py6 KB
  • tests/test_posterior_sample_approximation.py1.2 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.