贝塔分布。
继承自: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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
