All Projects → pyro-ppl → Funsor

pyro-ppl / Funsor

Licence: apache-2.0
Functional tensors for probabilistic programming

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Funsor

Mantid
Main repository for Mantid code
Stars: ✭ 150 (-8.54%)
Mutual labels:  numpy
Cam board
Turn web cam into a black / white board
Stars: ✭ 157 (-4.27%)
Mutual labels:  numpy
Py
Repository to store sample python programs for python learning
Stars: ✭ 4,154 (+2432.93%)
Mutual labels:  numpy
Alphalens
Performance analysis of predictive (alpha) stock factors
Stars: ✭ 2,130 (+1198.78%)
Mutual labels:  numpy
Rnn lstm from scratch
How to build RNNs and LSTMs from scratch with NumPy.
Stars: ✭ 156 (-4.88%)
Mutual labels:  numpy
Numsca
numsca is numpy for scala
Stars: ✭ 160 (-2.44%)
Mutual labels:  numpy
Stb Tester
Automated Testing for Set-Top Boxes and Smart TVs
Stars: ✭ 148 (-9.76%)
Mutual labels:  numpy
Pytubes
A module for getting data into python from large data sources
Stars: ✭ 164 (+0%)
Mutual labels:  numpy
Orjson
Fast, correct Python JSON library supporting dataclasses, datetimes, and numpy
Stars: ✭ 2,595 (+1482.32%)
Mutual labels:  numpy
Mobulaop
A Simple & Flexible Cross Framework Operators Toolkit
Stars: ✭ 161 (-1.83%)
Mutual labels:  numpy
Lits Liver Tumor Segmentation Challenge
LiTS - Liver Tumor Segmentation Challenge
Stars: ✭ 153 (-6.71%)
Mutual labels:  numpy
Color recognition
🎨 Color recognition & classification & detection on webcam stream / on video / on single image using K-Nearest Neighbors (KNN) is trained with color histogram features by OpenCV.
Stars: ✭ 154 (-6.1%)
Mutual labels:  numpy
Cheatsheets.pdf
📚 Various cheatsheets in PDF
Stars: ✭ 159 (-3.05%)
Mutual labels:  numpy
Machine Learning With Python
Practice and tutorial-style notebooks covering wide variety of machine learning techniques
Stars: ✭ 2,197 (+1239.63%)
Mutual labels:  numpy
Pywt
We're moving. Please visit https://github.com/PyWavelets
Stars: ✭ 161 (-1.83%)
Mutual labels:  numpy
Word2vec Spam Filter
Using word vectors to classify spam messages
Stars: ✭ 149 (-9.15%)
Mutual labels:  numpy
Gasyori100knock
image processing codes to understand algorithm
Stars: ✭ 1,988 (+1112.2%)
Mutual labels:  numpy
Cython Blis
💥 Fast matrix-multiplication as a self-contained Python library – no system dependencies!
Stars: ✭ 165 (+0.61%)
Mutual labels:  numpy
Ta
Technical Analysis Library using Pandas and Numpy
Stars: ✭ 2,649 (+1515.24%)
Mutual labels:  numpy
Kalman Filter
Kalman Filter implementation in Python using Numpy only in 30 lines.
Stars: ✭ 161 (-1.83%)
Mutual labels:  numpy

Build Status Latest Version Documentation Status

Funsor

Funsor is a tensor-like library for functions and distributions.

See Functional tensors for probabilistic programming for a system description.

Installing

Install using pip:

Funsor supports Python 3.6+.

pip install funsor

Install from source:

git clone [email protected]:pyro-ppl/funsor.git
cd funsor
git checkout master
pip install .

Using funsor

Funsor can be used through a number of interfaces:

  • Funsors can be used directly for probabilistic computations, using PyTorch optimizers in a standard training loop. Start with these examples: discrete_hmm, eeg_slds, kalman_filter, pcfg, sensor, slds, and vae.
  • Funsors can be used to implement custom inference algorithms within Pyro, using custom elbo implementations in standard pyro.infer.SVI training. See these examples: mixed_hmm and bart forecasting.
  • funsor.pyro provides a number of Pyro-compatible (and PyTorch-compatible) distribution classes that use funsors under the hood, as well utilities to convert between funsors and distributions.
  • funsor.minipyro provides a limited alternate backend for the Pyro probabilistic programming language, and can perform some ELBO computations exactly.

Design

See design doc.

The goal of this library is to generalize Pyro's delayed inference algorithms from discrete to continuous variables, and to create machinery to enable partially delayed sampling compatible with universality. To achieve this goal this library makes three orthogonal design choices:

  1. Open terms are objects. Funsors generalize the tensor interface to also cover arbitrary functions of multiple variables ("inputs"), where variables may be integers, real numbers, or real tensors. Function evaluation / substitution is the basic operation, generalizing tensor indexing. This allows probability distributions to be first-class Funsors and make use of existing tensor machinery, for example we can generalize tensor contraction to computing analytic integrals in conjugate probabilistic models.

  2. Support nonstandard interpretation. Funsors support user-defined interpretations, including, eager, lazy, mixed eager+lazy, memoized (like opt_einsum's sharing), and approximate interpretations like Monte Carlo approximations of integration operations (e.g. .sum() over a funsor dimension).

  3. Named dimensions. Substitution is the most basic operation of Funsors. To avoid the difficulties of broadcasting and advanced indexing in positionally-indexed tensor libraries, all Funsor dimensions are named. Indexing uses the .__call__() method and can be interpreted as substitution (with well-understood semantics). Funsors are viewed as algebraic expressions with one algebraic free variable per dimension. Each dimension is either covariant (an output) or contravariant (an input).

Using funsor we can easily implement Pyro-style delayed sampling, roughly:

trace_log_prob = 0.

def pyro_sample(name, dist, obs=None):
    assert isinstance(dist, Funsor)
    if obs is not None:
        value = obs
    elif lazy:
        # delayed sampling (like Pyro's parallel enumeration)
        value = funsor.Variable(name, dist.support)
    else:
        value = dist.sample('value')[0]['value']

    # save log_prob in trace
    trace_log_prob += dist(value)

    return value

# ...later during inference...
loss = -trace_log_prob.reduce(logaddexp)  # collapses delayed variables

See funsor/minipyro.py for complete implementation.

Related projects

Citation

If you use Funsor, please consider citing:

@article{obermeyer2019functional,
  author = {Obermeyer, Fritz and Bingham, Eli and Jankowiak, Martin and
            Phan, Du and Chen, Jonathan P},
  title = {{Functional Tensors for Probabilistic Programming}},
  journal = {arXiv preprint arXiv:1910.10775},
  year = {2019}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].