貝塔分布。
繼承自:Distribution
用法
tf.compat.v1.distributions.Beta(
    concentration1=None, concentration0=None, validate_args=False,
    allow_nan_stats=True, name='Beta'
)參數
- 
concentration1正浮點Tensor表示平均成功次數;又名"alpha"。暗示self.dtype和self.batch_shape,即concentration1.shape = [N1, N2, ..., Nm] = self.batch_shape。
- 
concentration0正浮點Tensor表示平均失敗次數;又名"beta"。否則具有與concentration1相同的語義。
- 
validate_argsPythonbool,默認False。盡管可能會降低運行時性能,但檢查True分發參數的有效性時。當False無效輸入可能會默默呈現不正確的輸出。
- 
allow_nan_statsPythonbool,默認True。當True時,統計信息(例如,均值、眾數、方差)使用值“NaN”來指示結果未定義。當False時,如果一個或多個統計數據的批處理成員未定義,則會引發異常。
- 
namePythonstr名稱以此類創建的 Ops 為前綴。
屬性
- 
allow_nan_statsPythonbool說明未定義統計信息時的行為。統計數據在有意義時返回 +/- 無窮大。例如,柯西分布的方差是無窮大的。但是,有時統計數據是未定義的,例如,如果分布的 pdf 在分布的支持範圍內沒有達到最大值,則模式是未定義的。如果均值未定義,則根據定義,方差未定義。例如: df = 1 的 Student's T 的平均值是未定義的(沒有明確的方式說它是 + 或 - 無窮大),因此方差 = E[(X - mean)**2] 也是未定義的。 
- 
batch_shape來自單個事件索引的單個樣本的形狀作為TensorShape.可能部分定義或未知。 批次維度是該分布的獨立、不同參數化的索引。 
- 
concentration0與0結果相關的濃度參數。
- 
concentration1與1結果相關的濃度參數。
- 
dtypeTensor的DType由此Distribution處理。
- 
event_shape單個批次的單個樣品的形狀作為TensorShape.可能部分定義或未知。 
- 
name此Distribution創建的所有操作前的名稱。
- 
parameters用於實例化此Distribution的參數字典。
- 
reparameterization_type說明如何重新參數化分布中的樣本。目前這是靜態實例 distributions.FULLY_REPARAMETERIZED或distributions.NOT_REPARAMETERIZED之一。
- 
total_concentration濃度參數的總和。
- 
validate_argsPythonbool表示啟用了可能昂貴的檢查。
使用參數concentration1(又名"alpha")和concentration0(又名"beta")在(0, 1)區間上定義Beta分布。
數學細節
概率密度函數 (pdf) 是,
pdf(x; alpha, beta) = x**(alpha - 1) (1 - x)**(beta - 1) / Z
Z = Gamma(alpha) Gamma(beta) / Gamma(alpha + beta)其中:
- concentration1 = alpha,
- concentration0 = beta,
- Z是歸一化常數,並且,
- Gamma是伽瑪函數。
濃度參數表示 1 或 0 的平均總計數,即
concentration1 = alpha = mean * total_concentration
concentration0 = beta  = (1. - mean) * total_concentration其中 (0, 1) 和 total_concentration 中的 mean 是表示平均值的正實數 total_count = concentration1 + concentration0 。
分布參數在所有函數中自動廣播;有關詳細信息,請參見示例。
警告:由於有限的精度,樣本可能為零。當某些濃度非常小時,這種情況會更頻繁地發生。確保在計算密度之前將樣本四舍五入到np.finfo(dtype).tiny。
該分布的樣本被重新參數化(路徑可微)。導數是使用 (Figurnov et al., 2018) 中說明的方法計算的。
例子
import tensorflow_probability as tfp
tfd = tfp.distributions
# Create a batch of three Beta distributions.
alpha = [1, 2, 3]
beta = [1, 2, 3]
dist = tfd.Beta(alpha, beta)
dist.sample([4, 5])  # Shape [4, 5, 3]
# `x` has three batch entries, each with two samples.
x = [[.1, .4, .5],
     [.2, .3, .5]]
# Calculate the probability of each pair of samples under the corresponding
# distribution in `dist`.
dist.prob(x)         # Shape [2, 3]# Create batch_shape=[2, 3] via parameter broadcast:
alpha = [[1.], [2]]      # Shape [2, 1]
beta = [3., 4, 5]        # Shape [3]
dist = tfd.Beta(alpha, beta)
# alpha broadcast as:[[1., 1, 1,],
#                      [2, 2, 2]]
# beta broadcast as: [[3., 4, 5],
#                      [3, 4, 5]]
# batch_Shape [2, 3]
dist.sample([4, 5])  # Shape [4, 5, 2, 3]
x = [.2, .3, .5]
# x will be broadcast as [[.2, .3, .5],
#                         [.2, .3, .5]],
# thus matching batch_shape [2, 3].
dist.prob(x)         # Shape [2, 3]計算樣本的梯度 w.r.t.參數:
alpha = tf.constant(1.0)
beta = tf.constant(2.0)
dist = tfd.Beta(alpha, beta)
samples = dist.sample(5)  # Shape [5]
loss = tf.reduce_mean(tf.square(samples))  # Arbitrary loss function
# Unbiased stochastic gradients of the loss function
grads = tf.gradients(loss, [alpha, beta])參考:
隱式重新參數化梯度:Figurnov 等人,2018 (pdf)
相關用法
- Python tf.compat.v1.distributions.Beta.quantile用法及代碼示例
- Python tf.compat.v1.distributions.Beta.kl_divergence用法及代碼示例
- Python tf.compat.v1.distributions.Beta.log_cdf用法及代碼示例
- Python tf.compat.v1.distributions.Beta.covariance用法及代碼示例
- Python tf.compat.v1.distributions.Beta.cdf用法及代碼示例
- Python tf.compat.v1.distributions.Beta.log_survival_function用法及代碼示例
- Python tf.compat.v1.distributions.Beta.stddev用法及代碼示例
- Python tf.compat.v1.distributions.Beta.cross_entropy用法及代碼示例
- Python tf.compat.v1.distributions.Beta.survival_function用法及代碼示例
- Python tf.compat.v1.distributions.Beta.variance用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.covariance用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.survival_function用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.kl_divergence用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.log_survival_function用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.log_cdf用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.stddev用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cdf用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.quantile用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.variance用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.distributions.Beta。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
