Skip to main content

Logo

A Python package collecting awesome MCMC sampling algorithms.
Explore the docs »

Examples | Report Bug | Request Feature


Table of Contents

Why use Racecar?

  • Racecar is a lightweight Python library for sampling distributions in high dimensions using cutting-edge algorithms. It can also be used for rapid prototyping of novel methods and application to large problems.
  • Pass a function evaluating the log posterior and/or its gradient, and away you go. Ideal for usage with big data applications, neural networks, regression, mixture modelling, and all sorts of Bayesian inference and sampling problems.
  • Easily to use and simple to extend with new methods and use cases.
  • Designed for use with stochastic gradients in mind.

Results from an inference experiment

Examples

Quickstart example

We will sample points from the one-dimensional distribution using the random walk Metropolis algorithm, and then plot the results.

# Import racecar and numpy
import racecar as rc
import numpy as np

# Define the target log posterior function
# Note we only need it up to a constant multiple, so we do not need to
# know its normalization constant.
def log_posterior(x):
  return {
  'llh' : -( np.cos(2*x) + x**2/12 )
  }

# Create the sampler object and use Random Walk Metropolis
initial_condition = [0]
learning_rate = 0.5
S = rc.sampler(initial_condition, learning_rate, log_posterior, algo="RWMetropolis")

# Sample some points, outputting arrays of the position and the log posterior
number_of_points = 100000
Pos_traj, LLH_traj = S.sample(number_of_points, output=['pos','llh'])

# Plot the results using matplotlib

Results

More examples

Some more detailed examples are given in the Jupyter notebooks below

Installation

You can install the package from source by cloning this repo and using setup.py, the only dependencies are on numpy and scipy. Otherwise it is available on pip via

pip install racecar

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Made by Charles Matthews - www.cmatthe.ws - mail@cmatthe.ws

Project Link: https://github.com/c-matthews/racecar

Release files for racecar 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for racecar 0.0.11
File Size Uploaded
racecar-0.0.11.tar.gz 13.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for racecar 0.0.11
File Interpreter ABI Platform
racecar-0.0.11-py3-none-any.whl Python 3 none any Details

Total release size: 31.8 kB

Release files / racecar-0.0.11.tar.gz

Download URL racecar-0.0.11.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f546c39c08d854047c5670bf1668ba3c700015d1443167d155eb6a321e322633
BLAKE2b-256 checksum
How to use checksums
1c0b5a31ea2c5095d29e44907d5aee5a15a4cb8b856641a7d273a04356ab56be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Release files / racecar-0.0.11-py3-none-any.whl

Download URL racecar-0.0.11-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1fc8825b3b085b9a8f20e0b5e6c16a3b061c7481ac0e806f8205c8f5c3896718
BLAKE2b-256 checksum
How to use checksums
230e4e464d7d1b03060b269fb4648db3ba3e686b7608bdc44c8f7c6e814182b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.0.11 This release

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page