TensorFlow Probability 是一個用於機率推理和統計分析的程式庫。

import tensorflow as tf
import tensorflow_probability as tfp

# Pretend to load synthetic data set.
features = tfp.distributions.Normal(loc=0., scale=1.).sample(int(100e3))
labels = tfp.distributions.Bernoulli(logits=1.618 * features).sample()

# Specify model.
model = tfp.glm.Bernoulli()

# Fit model given data.
coeffs, linear_response, is_converged, num_iter = tfp.glm.fit(
    model_matrix=features[:, tf.newaxis],
    response=tf.cast(labels, dtype=tf.float32),
    model=model)
# ==> coeffs is approximately [1.618] (We're golden!)
Notebook 中執行
TensorFlow Probability (TFP) 是一個以 TensorFlow 為基礎建構的 Python 程式庫,可讓您輕鬆地在現代硬體 (TPU、GPU) 上結合機率模型和深度學習。它適用於想要編碼領域知識以瞭解資料並做出預測的資料科學家、統計學家、機器學習研究人員和從業人員。TFP 包含
  • 多種機率分佈和雙射函數。
  • 用於建構深度機率模型的工具,包括機率層和 `JointDistribution` 抽象化。
  • 變分推論和馬可夫鏈蒙地卡羅法。
  • 最佳化工具,例如 Nelder-Mead、BFGS 和 SGLD。
由於 TFP 繼承了 TensorFlow 的優點,因此您可以在模型探索和生產的整個生命週期中使用單一語言來建構、擬合和部署模型。TFP 是開放原始碼,可在 GitHub 上取得。若要開始使用,請參閱《TensorFlow Probability 指南》。