Skip to main content

Accelerate Sequential Posterior Inference via REuse

Project description

aspire: Accelerated Sequential Posterior Inference via REuse

DOI PyPI Documentation Status tests

aspire is a framework for reusing existing posterior samples to obtain new results at a reduced cost.

Installation

aspire can be installed from PyPI using pip. By default, you need to install one of the backends for the normalizing flows, either torch or jax. We also recommend installing minipcn if using the smc sampler:

Torch

We recommend installing torch manually to ensure correct CPU/CUDA versions are installed. See the PyTorch installation instructions for more details.

pip install aspire-inference[torch,minipcn]

Jax:

We recommend install jax manually to ensure the correct GPU/CUDA versions are installed. See the jax documentation for details

pip install aspire-inference[jax,minipcn]

Important: the name of aspire on PyPI is aspire-inference but once installed the package can be imported and used as aspire.

Quickstart

import numpy as np
from aspire import Aspire, Samples

# Define a log-likelihood and log-prior
def log_likelihood(samples):
    x = samples.x
    return -0.5 * np.sum(x**2, axis=-1)

def log_prior(samples):
    return -0.5 * np.sum(samples.x**2, axis=-1)

# Create the initial samples
init = Samples(np.random.normal(size=(2_000, 4)))

# Define the aspire object
aspire = Aspire(
    log_likelihood=log_likelihood,
    log_prior=log_prior,
    dims=4,
    parameters=[f"x{i}" for i in range(4)],
)

# Fit the normalizing flow
aspire.fit(init, n_epochs=20)

# Sample the posterior
posterior = aspire.sample_posterior(
    sampler="smc",
    n_samples=500,
    sampler_kwargs=dict(n_steps=100),
)

# Plot the posterior distribution
posterior.plot_corner()

Documentation

See the documentation on ReadTheDocs.

Citation

If you use aspire in your work please cite the DOI and paper.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aspire_inference-0.1.0a20.tar.gz (88.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aspire_inference-0.1.0a20-py3-none-any.whl (67.8 kB view details)

Uploaded Python 3

File details

Details for the file aspire_inference-0.1.0a20.tar.gz.

File metadata

  • Download URL: aspire_inference-0.1.0a20.tar.gz
  • Upload date:
  • Size: 88.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for aspire_inference-0.1.0a20.tar.gz
Algorithm Hash digest
SHA256 69b910529b1180d1ae65eb4b8d3fb2de0ecbf2265ec21c6593301538c7efab2e
MD5 9a2d0b36c03353c2fe22635d53e9f9de
BLAKE2b-256 6282fdea81e6670fba4705374f3653dd3075c2bd92595f8941e94732f418857b

See more details on using hashes here.

Provenance

The following attestation bundles were made for aspire_inference-0.1.0a20.tar.gz:

Publisher: publish.yml on mj-will/aspire

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aspire_inference-0.1.0a20-py3-none-any.whl.

File metadata

File hashes

Hashes for aspire_inference-0.1.0a20-py3-none-any.whl
Algorithm Hash digest
SHA256 9a18a81d104e27af4527e91b844856e844a026ae2da595fc01b83ccadb371784
MD5 e4fd6cf884b4fd87013045f3d324a5d1
BLAKE2b-256 b8cfc233bc3528e09702b0e7385e0b97ab4851b98acf2bb3c5c1fd6835962f37

See more details on using hashes here.

Provenance

The following attestation bundles were made for aspire_inference-0.1.0a20-py3-none-any.whl:

Publisher: publish.yml on mj-will/aspire

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page