samplex
Package of useful sampling algorithms written in MLX. We plan on exploring how a combination of unified memory (by exploiting GPU and CPU together) and auto-diff can be used to get highly efficient and robust sampling locally on your Mac.
Please get in touch if you're interested in contributing (tedwards2412@gmail.com and nash.sabti@gmail.com)!
Installation
pip install samplex
Basic Usage
For a full example, please see the examples folder. Here is the basic structure for linear regression:
from samplex.samplex import samplex
from samplex.samplers import MH_Gaussian_sampler
# First lets generate some data
x = mx.linspace(-5, 5, 20)
err = mx.random.normal(x.shape)
y = b_true * x**2 + m_true * x + c_true + err
# Our target distribution is just a line
def log_target_distribution(theta, data):
m, c, b = theta
x, y, sigma = data
model = b * x**2 + m * x + c
residual = y - model
return sum(-0.5 * (residual**2 / sigma**2))
# The sampler assumes it gets a target distribution with a single input vector theta
logtarget = lambda theta: log_target_distribution(theta, (x, y, err))
# Here are the sampler settings
Nwalkers = 32
Ndim = 3
Nsteps = 10_000
cov_matrix = mx.array([0.01, 0.01, 0.01])
jumping_factor = 1.0
theta0_array = mx.random.uniform(
mx.array([m_min, c_min, b_min]),
mx.array([m_max, c_max, b_max]),
(Nwalkers, Ndim),
)
# Firstly we instantiate a samplex class and then run!
sampler = MH_Gaussian_sampler(logtarget)
sam = samplex(sampler, Nwalkers)
sam.run(Nsteps, theta0_array, cov_matrix, jumping_factor)
Next Steps:
- Get NUTs/HMC running
- Get Ensemble sampler running (emcee)
- Refine plotting
- Add helper functions for variety of priors
- Treating parameters with different update speeds
- Add file of priors and include in target distribution
- Include autocorrelation calculation for steps
Metadata
Release files for samplex 0.0.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 | Provenance | Actions |
|---|---|---|---|---|
| samplex-0.0.2.tar.gz | 9.4 kB | Without provenance | Details for samplex-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| samplex-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for samplex-0.0.2-py3-none-any.whl |
Total release size: 18.5 kB
Release files / samplex-0.0.2.tar.gz
| Download URL | samplex-0.0.2.tar.gz |
|---|---|
| Size | 9.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
903112a33dbcab71d3f1c37a3cb81a4dd023aa126f35e43ca78a9660e2e7281c
|
|
BLAKE2b-256 checksum How to use checksums |
1d6ea4360305cae530cc41b83a2800ac47a0889118cd67d0978c0fd910513c2c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.1
|
Release files / samplex-0.0.2-py3-none-any.whl
| Download URL | samplex-0.0.2-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9247912cacd545bef373ab9f380dfec619da15d2323333bf66f6cfd6a7f48b4d
|
|
BLAKE2b-256 checksum How to use checksums |
87e1d2c426aea56ea9a170e4434b0c3a8cb05360e4ff54e4324ae983a705f8e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.12.1
|
Security for samplex 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.