狄利克雷分布。
继承自:Distribution
用法
tf.compat.v1.distributions.Dirichlet(
    concentration, validate_args=False, allow_nan_stats=True,
    name='Dirichlet'
)参数
- 
concentration正浮点Tensor表示类的平均出现次数;又名"alpha"。暗示self.dtype和self.batch_shape,self.event_shape,即如果concentration.shape = [N1, N2, ..., Nm, k]则batch_shape = [N1, N2, ..., Nm]和event_shape = [k]。
- 
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.可能部分定义或未知。 批次维度是该分布的独立、不同参数化的索引。 
- 
concentration浓度参数;该坐标的预期计数。
- 
dtypeTensor的DType由此Distribution处理。
- 
event_shape单个批次的单个样品的形状作为TensorShape.可能部分定义或未知。 
- 
name此Distribution创建的所有操作前的名称。
- 
parameters用于实例化此Distribution的参数字典。
- 
reparameterization_type说明如何重新参数化分布中的样本。目前这是静态实例 distributions.FULLY_REPARAMETERIZED或distributions.NOT_REPARAMETERIZED之一。
- 
total_concentrationlast dim of 浓度参数的总和。
- 
validate_argsPythonbool表示启用了可能昂贵的检查。
狄利克雷分布是在 (k-1)-单纯形上定义的,使用正的、长度为 k 的向量 concentration (k > 1)。 Dirichlet 与 k = 2 时的 Beta 分布相同。
数学细节
Dirichlet 是开放的 (k-1) -simplex 上的分布,即
S^{k-1} = { (x_0, ..., x_{k-1}) in R^k:sum_j x_j = 1 and all_j x_j > 0 }.概率密度函数 (pdf) 是,
pdf(x; alpha) = prod_j x_j**(alpha_j - 1) / Z
Z = prod_j Gamma(alpha_j) / Gamma(sum_j alpha_j)其中:
- x in S^{k-1},即- (k-1)-simplex,
- concentration = alpha = [alpha_0, ..., alpha_{k-1}],- alpha_j > 0,
- Z是归一化常数,也就是多元 beta 函数,并且,
- Gamma是伽玛函数。
concentration 表示类出现的平均总计数,即
concentration = alpha = mean * total_concentration其中 S^{k-1} 和 total_concentration 中的 mean 是一个正实数,表示平均总计数。
分布参数在所有函数中自动广播;有关详细信息,请参见示例。
警告:由于有限的精度,样本的某些分量可能为零。当某些浓度非常小时,这种情况会更频繁地发生。确保在计算密度之前将样本四舍五入到np.finfo(dtype).tiny。
该分布的样本被重新参数化(路径可微)。导数是使用 (Figurnov et al., 2018) 中说明的方法计算的。
例子
import tensorflow_probability as tfp
tfd = tfp.distributions
# Create a single trivariate Dirichlet, with the 3rd class being three times
# more frequent than the first. I.e., batch_shape=[], event_shape=[3].
alpha = [1., 2, 3]
dist = tfd.Dirichlet(alpha)
dist.sample([4, 5])  # shape:[4, 5, 3]
# x has one sample, one batch, three classes:
x = [.2, .3, .5]   # shape:[3]
dist.prob(x)       # shape:[]
# x has two samples from one batch:
x = [[.1, .4, .5],
     [.2, .3, .5]]
dist.prob(x)         # shape:[2]
# alpha will be broadcast to shape [5, 7, 3] to match x.
x = [[...]]   # shape:[5, 7, 3]
dist.prob(x)  # shape:[5, 7]# Create batch_shape=[2], event_shape=[3]:
alpha = [[1., 2, 3],
         [4, 5, 6]]   # shape:[2, 3]
dist = tfd.Dirichlet(alpha)
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]计算样本的梯度 w.r.t.参数:
alpha = tf.constant([1.0, 2.0, 3.0])
dist = tfd.Dirichlet(alpha)
samples = dist.sample(5)  # Shape [5, 3]
loss = tf.reduce_mean(tf.square(samples))  # Arbitrary loss function
# Unbiased stochastic gradients of the loss function
grads = tf.gradients(loss, alpha)参考:
隐式重新参数化梯度:Figurnov 等人,2018 (pdf)
相关用法
- Python tf.compat.v1.distributions.Dirichlet.covariance用法及代码示例
- Python tf.compat.v1.distributions.Dirichlet.stddev用法及代码示例
- Python tf.compat.v1.distributions.Dirichlet.kl_divergence用法及代码示例
- Python tf.compat.v1.distributions.Dirichlet.cross_entropy用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.log_survival_function用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.survival_function用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.quantile用法及代码示例
- Python tf.compat.v1.distributions.Dirichlet.cdf用法及代码示例
- Python tf.compat.v1.distributions.Dirichlet.survival_function用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.log_cdf用法及代码示例
- Python tf.compat.v1.distributions.Dirichlet.log_survival_function用法及代码示例
- Python tf.compat.v1.distributions.Dirichlet.log_cdf用法及代码示例
- Python tf.compat.v1.distributions.Dirichlet.variance用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.covariance用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.cdf用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.variance用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.kl_divergence用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.stddev用法及代码示例
- Python tf.compat.v1.distributions.DirichletMultinomial.cross_entropy用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.distributions.Dirichlet。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
