Skip to main content

Logarithmantic Monte Carlo

Project description

ascl:1706.005 PyPi LGPL-3.0

Logarithmantic Monte Carlo (LMC)

Python code for Markov Chain Monte Carlo

Logarithmancy (n): divination by means of algorithms

What is this?

LMC (not to be confused with the Large Magellanic Cloud) is a bundle of Python code for performing Markov Chain Monte Carlo, which implements a few different multidimensional proposal strategies and (optionally parallel) adaptation methods. There are similar packages out there, notably pymc - LMC exists because I found the alternatives to be too inflexible for the work I was doing at the time. On the off chance that someone else is in the same boat, here it is.

The samplers currently included are Metropolis, slice, and the affine-invariant sampler popularized by emcee (Goodman & Weare 2010).

An abridged description of the package (from the help function) is copied here:

The module should be very flexible, but is designed with these things foremost in mind:
 1. use with expensive likelihood calculations which probably have a host of hard-to-modify
    code associated with them.
 2. making it straightforward to break the parameter space into subspaces which can be sampled
    using different proposal methods and at different rates. For example, if changing some
    parameters requires very expensive calulations in the likelihood, the other, faster
    parameters can be sampled at a higher rate. Or, some parameters may lend themselves to
    Gibbs sampling, while others may not, and these can be block updated independently.
 3. keeping the overhead low to facilitate large numbers of parameters. Some of this has been
    lost in the port from C++, but, for example, the package provides automatic tuning of the
    proposal covariance for block updating without needing to store traces of the parameters in
    memory.

Real-valued parameters are usually assumed, but the framework can be used with other types of
parameters, with suitable overloading of classes.

A byproduct of item (1) is that the user is expected to handle all aspects of the calculation of
the posterior. The module doesn't implement assignment of canned, standard priors, or automatic
discovery of shortcuts like conjugate Gibbs sampling. The idea is that the user is in the best
position to know how the details of the likelihood and priors should be implemented.

Communication between parallel chains can significantly speed up convergence. In parallel mode,
adaptive Updaters use information from all running chains to tune their proposals, rather than
only from their own chain. The Gelman-Rubin convergence criterion (ratio of inter- to intra-chain
variances) for each free parameter is also calculated. Parallelization is implemented in two ways;
see ?Updater for instructions on using each.
 1. Via MPI (using mpi4py). MPI adaptations are synchronous: when a chain reaches a communication
    point, it stops until all chains have caught up.
 2. Via the filesystem. When a chain adapts, it will write its covariance information to a file. It
    will then read in any information from other chains that is present in similar files, and
    incorporate it when tuning. This process is asynchronous; chains will not wait for one another;
    they will simply adapt using whatever information has been shared at the time.

Installation

Automatic

Install from PyPI by running pip install lmc.

Manual

Download lmc/lmc.py and put it somewhere on your PYTHONPATH. You will need to have the numpy package installed. The mpi4py package is optional, but highly recommended.

Usage and Help

Documentation can be found throughout lmc.py, mostly in the form of docstrings, so it’s also available through the Python interpreter. There’s also a help() function (near the top of the file, if you’re browsing) and an example() function (near the bottom).

The examples can also be browsed here.

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

lmc-0.2.1.tar.gz (22.7 kB view details)

Uploaded Source

Built Distribution

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

lmc-0.2.1-py3-none-any.whl (24.7 kB view details)

Uploaded Python 3

File details

Details for the file lmc-0.2.1.tar.gz.

File metadata

  • Download URL: lmc-0.2.1.tar.gz
  • Upload date:
  • Size: 22.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for lmc-0.2.1.tar.gz
Algorithm Hash digest
SHA256 7ec90c49c0d30cdf5d5328e3a7e565f67fed27ad71db4de10e32a6664d08164a
MD5 0e5af997b5970cb1e1bf96997b9a0090
BLAKE2b-256 c66b6089fb37148729c8a281aacfe6593a1dcdb654043b0a3b60606b5e148fb2

See more details on using hashes here.

File details

Details for the file lmc-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: lmc-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 24.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0.post20200714 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.10

File hashes

Hashes for lmc-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7bfb35bbcab0eb89bf34e59f231de320ea63e76f8ba9a7f46b2f19de8048ff8e
MD5 1b740920545432f064e0807940cd341d
BLAKE2b-256 a1a3129c7961d1c90a7e86247b75f28167b8ec8b905895502e6c0dcd0c5ade1a

See more details on using hashes here.

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