psiphy — Package for Statistical Inference of Physics
A Python package for cosmological parameter inference, providing tools for simulation-based inference (SBI), MCMC sampling, Fisher forecasting, and posterior diagnostics.
What's inside
| Module | Contents |
|---|---|
psiphy.mcmc |
MHSampler (emcee), NestedSampler (nautilus or dynesty, with Bayesian evidence), importance sampling and sequential_monte_carlo (likelihood tempering, evidence estimate) |
psiphy.utils.prior |
Uniform, log-uniform, Gaussian and mixture priors with one interface for all samplers (sample, log_prob, prior_transform) |
psiphy.sbi |
Likelihood-free inference: BOLFI (Bayesian optimisation), LFIRE (ratio estimation), rejection ABC |
psiphy.forecasting |
FisherMatrix: numerical Fisher forecasts with several estimators and parallel simulations |
psiphy.plotting |
Posterior diagnostics: triangle plots, credible intervals, z-scores, comparisons between posteriors |
psiphy.toy_models |
Simulators with known answers for testing and tutorials |
Quick example:
from psiphy.mcmc import MHSampler
from psiphy.utils.prior import UniformPrior
from psiphy.toy_models import NoisyLine
line = NoisyLine()
y_obs = line.simulate([-0.8, 5.0])
prior = UniformPrior({'slope': (-3, 3), 'intercept': (0, 10)})
sampler = MHSampler(lambda t: prior.log_prob(t) + line.log_prob(t, y_obs), n_walkers=32,
param_names=prior.names)
sampler.run(prior.sample(32), n_steps=2000)
sampler.summary()
Tutorials
Notebooks in examples/, also rendered in the documentation:
- MCMC sampling and priors
- Nested sampling and Bayesian evidence
- Importance sampling and SMC (includes a calibration check over many data sets)
- Likelihood-free inference: rejection ABC, BOLFI, LFIRE
- Fisher forecasting
- Plotting diagnostics
- Toy models
Installation
From PyPI:
pip install psiphy
Optional dependencies are grouped as extras: mcmc (emcee, dynesty, nautilus), sbi
(sbi, torch), hmc (JAX/blackjax, for the planned HMC sampler):
pip install "psiphy[mcmc]"
The latest development version from GitHub:
pip install git+https://github.com/sambit-giri/psiphy.git
For a local editable install (recommended for development):
git clone https://github.com/sambit-giri/psiphy.git
cd psiphy
pip install -e ".[dev]"
Running the tests
The test suite uses pytest. After installing with the dev extras:
pytest tests/ -v
Tests cover every module, checking samplers against analytic posteriors and evidences where these are known. New tests are added alongside each new module.
Contributing and feedback
Bug reports, feature requests, and questions are welcome — please open an issue on the GitHub issue tracker. Pull requests are also encouraged.
Metadata
Release files for psiphy 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| psiphy-0.1.2.tar.gz | 75.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| psiphy-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 148.1 kB
Release files / psiphy-0.1.2.tar.gz
| Download URL | psiphy-0.1.2.tar.gz |
|---|---|
| Size | 75.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0eb7fde6bac58491122b9a9361db52b636556435912e942d7cdf587d6f704060
|
|
BLAKE2b-256 checksum How to use checksums |
952bec3b6c925f6e4754950a510f0c484e37375a0046cdaf9c34b1c95309f56a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|
Release files / psiphy-0.1.2-py3-none-any.whl
| Download URL | psiphy-0.1.2-py3-none-any.whl |
|---|---|
| Size | 72.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
250b228ed21a57b48f695a1edd976d68336410a5526fd5db7ad05c976419d636
|
|
BLAKE2b-256 checksum How to use checksums |
ab7f2051f9d21c218c4c2a13236a019772ab383473d96542d261463d70acf7e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.11
|