- Notifications
You must be signed in to change notification settings - Fork1.1k
Probabilistic reasoning and statistical analysis in TensorFlow
License
tensorflow/probability
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
TensorFlow Probability is a library for probabilistic reasoning and statisticalanalysis in TensorFlow. As part of the TensorFlow ecosystem, TensorFlowProbability provides integration of probabilistic methods with deep networks,gradient-based inference via automatic differentiation, and scalability tolarge datasets and models via hardware acceleration (e.g., GPUs) and distributedcomputation.
TFP also works as "Tensor-friendly Probability" in pure JAX!:from tensorflow_probability.substrates import jax as tfp --Learn morehere.
Our probabilistic machine learning tools are structured as follows.
Layer 0: TensorFlow. Numerical operations. In particular, the LinearOperatorclass enables matrix-free implementations that can exploit special structure(diagonal, low-rank, etc.) for efficient computation. It is built and maintainedby the TensorFlow Probability team and is now part oftf.linalgin core TF.
Layer 1: Statistical Building Blocks
- Distributions (
tfp.distributions):A large collection of probabilitydistributions and related statistics with batch andbroadcastingsemantics. See theDistributions Tutorial. - Bijectors (
tfp.bijectors):Reversible and composable transformations of random variables. Bijectorsprovide a rich class of transformed distributions, from classical exampleslike thelog-normal distributionto sophisticated deep learning models such asmasked autoregressive flows.
Layer 2: Model Building
- Joint Distributions (e.g.,
tfp.distributions.JointDistributionSequential):Joint distributions over one or more possibly-interdependent distributions.For an introduction to modeling with TFP'sJointDistributions, check outthis colab - Probabilistic Layers (
tfp.layers):Neural network layers with uncertainty over the functions they represent,extending TensorFlow Layers.
Layer 3: Probabilistic Inference
- Markov chain Monte Carlo (
tfp.mcmc):Algorithms for approximating integrals via sampling. IncludesHamiltonian Monte Carlo,random-walk Metropolis-Hastings, and the ability to build custom transitionkernels. - Variational Inference (
tfp.vi):Algorithms for approximating integrals via optimization. - Optimizers (
tfp.optimizer):Stochastic optimization methods, extending TensorFlow Optimizers. IncludesStochastic Gradient Langevin Dynamics. - Monte Carlo (
tfp.monte_carlo):Tools for computing Monte Carlo expectations.
TensorFlow Probability is under active development. Interfaces may change at anytime.
Seetensorflow_probability/examples/for end-to-end examples. It includes tutorial notebooks such as:
- Linear Mixed Effects Models.A hierarchical linear model for sharing statistical strength across examples.
- Eight Schools.A hierarchical normal model for exchangeable treatment effects.
- Hierarchical Linear Models.Hierarchical linear models compared among TensorFlow Probability, R, and Stan.
- Bayesian Gaussian Mixture Models.Clustering with a probabilistic generative model.
- Probabilistic Principal Components Analysis.Dimensionality reduction with latent variables.
- Gaussian Copulas.Probability distributions for capturing dependence across random variables.
- TensorFlow Distributions: A Gentle Introduction.Introduction to TensorFlow Distributions.
- Understanding TensorFlow Distributions Shapes.How to distinguish between samples, batches, and events for arbitrarily shapedprobabilistic computations.
- TensorFlow Probability Case Study: Covariance Estimation.A user's case study in applying TensorFlow Probability to estimate covariances.
It also includes example scripts such as:
Representation learning with a latent code and variational inference.
- Vector-Quantized Autoencoder.Discrete representation learning with vector quantization.
- Disentangled Sequential Variational AutoencoderDisentangled representation learning over sequences with variational inference.
- Bayesian Neural Networks.Neural networks with uncertainty over their weights.
- Bayesian Logistic Regression.Bayesian inference for binary classification.
For additional details on installing TensorFlow, guidance installingprerequisites, and (optionally) setting up virtual environments, see theTensorFlow installation guide.
To install the latest stable version, run the following:
# Notes:# - The `--upgrade` flag ensures you'll get the latest version.# - The `--user` flag ensures the packages are installed to your user directory# rather than the system directory.# - TensorFlow 2 packages require a pip >= 19.0python -m pip install --upgrade --user pippython -m pip install --upgrade --user tensorflow tensorflow_probability
For CPU-only usage (and a smaller install), install withtensorflow-cpu.
To use a pre-2.0 version of TensorFlow, run:
python -m pip install --upgrade --user"tensorflow<2""tensorflow_probability<0.9"
Note: SinceTensorFlow isnot includedas a dependency of the TensorFlow Probability package (insetup.py), you mustexplicitly install the TensorFlow package (tensorflow ortensorflow-cpu).This allows us to maintain one package instead of separate packages for CPU andGPU-enabled TensorFlow. See theTFP release notes for moredetails about dependencies between TensorFlow and TensorFlow Probability.
There are also nightly builds of TensorFlow Probability under the pip packagetfp-nightly, which depends on one oftf-nightly ortf-nightly-cpu.Nightly builds include newer features, but may be less stable than theversioned releases. Both stable and nightly docs are availablehere.
python -m pip install --upgrade --user tf-nightly tfp-nightly
You can also install from source. This requires theBazel build system. It is highly recommended that you installthe nightly build of TensorFlow (tf-nightly) before trying to buildTensorFlow Probability from source. The most recent version of Bazel that TFPcurrently supports is 6.4.0; support for 7.0.0+ is WIP.
# sudo apt-get install bazel git python-pip # Ubuntu; others, see above links.python -m pip install --upgrade --user tf-nightlygit clone https://github.com/tensorflow/probability.gitcd probabilitybazel build --copt=-O3 --copt=-march=native :pip_pkgPKGDIR=$(mktemp -d)./bazel-bin/pip_pkg$PKGDIRpython -m pip install --upgrade --user$PKGDIR/*.whl
As part of TensorFlow, we're committed to fostering an open and welcomingenvironment.
- Stack Overflow: Askor answer technical questions.
- GitHub: Report bugs ormake feature requests.
- TensorFlow Blog: Stay up to date on contentfrom the TensorFlow team and best articles from the community.
- Youtube Channel: Follow TensorFlow shows.
- tfprobability@tensorflow.org:Open mailing list for discussion and questions.
See theTensorFlow Community page formore details. Check out our latest publicity here:
- Coffee with a Googler: Probabilistic Machine Learning in TensorFlow
- Introducing TensorFlow Probability
We're eager to collaborate with you! SeeCONTRIBUTING.mdfor a guide on how to contribute. This project adheres to TensorFlow'scode of conduct. By participating, you are expected touphold this code.
If you use TensorFlow Probability in a paper, please cite:
- TensorFlow Distributions. Joshua V. Dillon, Ian Langmore, Dustin Tran,Eugene Brevdo, Srinivas Vasudevan, Dave Moore, Brian Patton, Alex Alemi, MattHoffman, Rif A. Saurous.arXiv preprint arXiv:1711.10604, 2017.
(We're aware there's a lot more to TensorFlow Probability than Distributions, but the Distributions paper lays out our vision and is a fine thing to cite for now.)
About
Probabilistic reasoning and statistical analysis in TensorFlow
Topics
Resources
License
Code of conduct
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.