伽馬分布。
繼承自:Distribution
用法
tf.compat.v1.distributions.Gamma(
    concentration, rate, validate_args=False, allow_nan_stats=True,
    name='Gamma'
)參數
- 
concentration浮點張量,分布的濃度參數。必須隻包含正值。
- 
rate浮點張量,分布的反比例參數。必須隻包含正值。
- 
validate_argsPythonbool,默認False。盡管可能會降低運行時性能,但檢查True分發參數的有效性時。當False無效輸入可能會默默呈現不正確的輸出。
- 
allow_nan_statsPythonbool,默認True。當True時,統計信息(例如,均值、眾數、方差)使用值“NaN”來指示結果未定義。當False時,如果一個或多個統計數據的批處理成員未定義,則會引發異常。
- 
namePythonstr名稱以此類創建的 Ops 為前綴。
拋出
- 
TypeError如果concentration和rate是不同的數據類型。
屬性
- 
allow_nan_statsPythonbool說明未定義統計信息時的行為。統計數據在有意義時返回 +/- 無窮大。例如,柯西分布的方差是無窮大的。但是,有時統計數據是未定義的,例如,如果分布的 pdf 在分布的支持範圍內沒有達到最大值,則模式是未定義的。如果均值未定義,則根據定義,方差未定義。例如: df = 1 的 Student's T 的平均值是未定義的(沒有明確的方式說它是 + 或 - 無窮大),因此方差 = E[(X - mean)**2] 也是未定義的。 
- 
batch_shape來自單個事件索引的單個樣本的形狀作為TensorShape.可能部分定義或未知。 批次維度是該分布的獨立、不同參數化的索引。 
- 
concentration濃度參數。
- 
dtypeTensor的DType由此Distribution處理。
- 
event_shape單個批次的單個樣品的形狀作為TensorShape.可能部分定義或未知。 
- 
name此Distribution創建的所有操作前的名稱。
- 
parameters用於實例化此Distribution的參數字典。
- 
rate速率參數。
- 
reparameterization_type說明如何重新參數化分布中的樣本。目前這是靜態實例 distributions.FULLY_REPARAMETERIZED或distributions.NOT_REPARAMETERIZED之一。
- 
validate_argsPythonbool表示啟用了可能昂貴的檢查。
Gamma 分布是使用參數concentration(又名"alpha")和rate(又名"beta")在正實數上定義的。
數學細節
概率密度函數 (pdf) 是,
pdf(x; alpha, beta, x > 0) = x**(alpha - 1) exp(-x beta) / Z
Z = Gamma(alpha) beta**(-alpha)其中:
- concentration = alpha,- alpha > 0,
- rate = beta,- beta > 0,
- Z是歸一化常數,並且,
- Gamma是伽瑪函數。
累積密度函數 (cdf) 為,
cdf(x; alpha, beta, x > 0) = GammaInc(alpha, beta x) / Gamma(alpha)其中 GammaInc 是下不完全 Gamma 函數。
這些參數可以通過它們與均值和標準差的關係來直觀理解,
concentration = alpha = (mean / stddev)**2
rate = beta = mean / stddev**2 = concentration / mean分布參數在所有函數中自動廣播;有關詳細信息,請參見示例。
警告:這種分布的樣本總是非負的。但是,小於 np.finfo(dtype).tiny 的樣本會被四舍五入到這個值,所以它出現的頻率比它應該的要高。僅當concentration 非常小或rate 非常大時才會注意到這一點。請參閱 tf.random.gamma 文檔字符串中的注釋。
該分布的樣本被重新參數化(路徑可微)。導數是使用 (Figurnov et al., 2018) 中說明的方法計算的。
例子
import tensorflow_probability as tfp
tfd = tfp.distributions
dist = tfd.Gamma(concentration=3.0, rate=2.0)
dist2 = tfd.Gamma(concentration=[3.0, 4.0], rate=[2.0, 3.0])計算樣本的梯度 w.r.t.參數:
concentration = tf.constant(3.0)
rate = tf.constant(2.0)
dist = tfd.Gamma(concentration, rate)
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, [concentration, rate])參考:
隱式重新參數化梯度:Figurnov 等人,2018 (pdf)
相關用法
- Python tf.compat.v1.distributions.Gamma.cdf用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.log_cdf用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.cross_entropy用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.stddev用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.covariance用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.quantile用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.log_survival_function用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.variance用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.kl_divergence用法及代碼示例
- Python tf.compat.v1.distributions.Gamma.survival_function用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.stddev用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.cross_entropy用法及代碼示例
- Python tf.compat.v1.distributions.Bernoulli.covariance用法及代碼示例
- Python tf.compat.v1.distributions.Normal.log_survival_function用法及代碼示例
- Python tf.compat.v1.distributions.Laplace.stddev用法及代碼示例
- Python tf.compat.v1.distributions.Multinomial.quantile用法及代碼示例
- Python tf.compat.v1.distributions.Uniform.log_survival_function用法及代碼示例
- Python tf.compat.v1.distributions.Normal.log_cdf用法及代碼示例
- Python tf.compat.v1.distributions.Laplace.cross_entropy用法及代碼示例
- Python tf.compat.v1.distributions.Dirichlet.covariance用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.compat.v1.distributions.Gamma。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
