跳转到主要内容

TensorFlow中的概率建模和统计推断

项目描述

TensorFlow Probability

TensorFlow Probability是一个在TensorFlow中进行概率推理和统计分析的库。作为TensorFlow生态系统的一部分,TensorFlow Probability提供了概率方法与深度网络的集成,通过自动微分进行基于梯度的推理,并通过硬件加速(例如,GPU)和分布式计算扩展到大型数据集和模型。

TFP 也可以在纯 JAX 中作为 "Tensor 友好概率" 使用!from tensorflow_probability.substrates import jax as tfp -- 了解更多信息 这里

我们的概率机器学习工具结构如下。

层 0:TensorFlow。 数值运算。特别是,LinearOperator 类可以实现无矩阵的实现,可以利用特殊的结构(对角线、低秩等)进行高效计算。它由 TensorFlow Probability 团队构建和维护,现在已包含在核心 TF 的 tf.linalg 中。

层 1:统计构建块

  • 分布(tfp.distributions):包含大量概率分布和相关统计,具有批处理和 广播 语义。请参阅 分布教程
  • 可逆变换(tfp.bijectors):随机变量的可逆和可组合变换。可逆变换提供了一类丰富的变换分布,从经典例子如对数正态分布到复杂的深度学习模型,如 掩码自回归流

层 2:模型构建

  • 联合分布(例如,tfp.distributions.JointDistributionSequential):一个或多个可能相互依赖的分布上的联合分布。有关使用 TFP 的 JointDistribution 进行建模的介绍,请参阅 此 colab
  • 概率层(tfp.layers):具有函数不确定性的神经网络层,扩展 TensorFlow Layers。

层 3:概率推理

TensorFlow Probability 正在积极开发中。接口可能随时更改。

示例

请参阅 tensorflow_probability/examples/ 以查看端到端示例。它包括以下教程笔记本

还包括以下示例脚本

利用潜在码和变分推理进行表示学习。

安装

有关安装 TensorFlow、安装先决条件和(可选)设置虚拟环境的更多信息,请参阅 TensorFlow 安装指南

稳定构建

要安装最新稳定版本,请运行以下命令

# 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.0
python -m pip install --upgrade --user pip
python -m pip install --upgrade --user tensorflow tensorflow_probability

对于仅 CPU 使用(以及较小的安装),使用 tensorflow-cpu 进行安装。

要使用 TensorFlow 的 2.0 以下版本,请运行

python -m pip install --upgrade --user "tensorflow<2" "tensorflow_probability<0.9"

注意:由于 TensorFlow 并未作为 TensorFlow 概率包(在 setup.py 中)的依赖项,因此您必须明确安装 TensorFlow 包(tensorflowtensorflow-cpu)。这允许我们维护一个包,而不是为 CPU 和 GPU 启用的 TensorFlow 维护单独的包。有关 TensorFlow 和 TensorFlow 概率之间依赖关系的更多详细信息,请参阅 TFP 发布说明

夜间构建

还有 TensorFlow 概率的夜间构建版本,在 pip 包 tfp-nightly 下,它依赖于 tf-nightlytf-nightly-cpu 之一。夜间构建包括新功能,但可能不如版本发布稳定。稳定和夜间文档均可在 此处 获取。

python -m pip install --upgrade --user tf-nightly tfp-nightly

从源代码安装

您还可以从源代码安装。这需要 Bazel 构建系统。强烈建议在尝试从源代码构建 TensorFlow 概率之前,先安装 TensorFlow 的夜间构建版本(tf-nightly)。TFP 当前支持的最新 Bazel 版本是 6.4.0;对 7.0.0+ 的支持正在进行中。

# sudo apt-get install bazel git python-pip  # Ubuntu; others, see above links.
python -m pip install --upgrade --user tf-nightly
git clone https://github.com/tensorflow/probability.git
cd probability
bazel build --copt=-O3 --copt=-march=native :pip_pkg
PKGDIR=$(mktemp -d)
./bazel-bin/pip_pkg $PKGDIR
python -m pip install --upgrade --user $PKGDIR/*.whl

社区

作为 TensorFlow 的一部分,我们致力于营造一个开放和包容的环境。

请访问TensorFlow社区页面获取更多信息。在此查看我们的最新宣传

贡献

我们渴望与您合作!请参阅CONTRIBUTING.md以了解如何贡献。此项目遵循TensorFlow的行为准则。通过参与,您应遵守此准则。

参考文献

如果您在论文中使用TensorFlow Probability,请引用

  • TensorFlow Distributions。 Joshua V. Dillon, Ian Langmore, Dustin Tran, Eugene Brevdo, Srinivas Vasudevan, Dave Moore, Brian Patton, Alex Alemi, Matt Hoffman, Rif A. Saurous. arXiv预印本arXiv:1711.10604, 2017.

(我们意识到TensorFlow Probability远不止于Distributions,但Distributions论文概述了我们的愿景,目前引用它是一个不错的选择。)

项目详情


发布历史 发布通知 | RSS订阅

下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

本版本没有可用的源分发文件。请参阅有关生成分发存档的教程。

构建分发

tensorflow_probability-0.24.0-py2.py3-none-any.whl (6.9 MB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持