如何计算两个tfp.distributions.Normal的重叠概率?
类似于在https://docs.python.org/3.8/library/statistics.html?highlight=normaldist#statistics.NormalDist中实现的方法
发布于 2021-06-22 19:04:25
下面是我基于statistics.NormalDiststatistics.NormalDist代码的实现:
dv = Y.variance() - X.variance()
dm = tf.math.abs(Y.mean() - X.mean())
if tf.reduce_sum(dv) == 0:
return 1.0 - tf.math.erf(
tf.math.divide(dm,
tf.math.multiply(
tf.constant(2, dtype=tf.float32),
tf.math.multiply(
X.stddev(),
tf.math.sqrt(tf.constant(2, dtype=tf.float32))))))
a = tf.math.multiply(X.mean(), Y.variance()) - tf.math.multiply(Y.mean(), X.variance())
b = tf.math.multiply(
tf.math.multiply(X.stddev(), Y.stddev()),
tf.math.sqrt(tf.math.pow(dm, 2) + tf.math.multiply(
dv,
tf.math.log(Y.variance() / X.variance()))))
x1 = (a + b) / dv
x2 = (a - b) / dv
return 1.0 - (tf.math.abs(Y.cdf(x1) - X.cdf(x1)) + tf.math.abs(Y.cdf(x2) - X.cdf(x2)))def norm_dist_overlap_prob_v1(X: tfp.distributions.Normal, Y: tfp.distributions.Normal):
dv = Y.variance() - X.variance()
dm = tf.math.abs(Y.mean() - X.mean())
if tf.reduce_sum(dv) == 0:
return 1.0 - tf.math.erf(
tf.math.divide(dm,
tf.math.multiply(
tf.constant(2, dtype=tf.float32),
tf.math.multiply(
X.stddev(),
tf.math.sqrt(tf.constant(2, dtype=tf.float32))))))
a = tf.math.multiply(X.mean(), Y.variance()) - tf.math.multiply(Y.mean(), X.variance())
b = tf.math.multiply(
tf.math.multiply(X.stddev(), Y.stddev()),
tf.math.sqrt(tf.math.pow(dm, 2) + tf.math.multiply(
dv,
tf.math.log(Y.variance() / X.variance()))))
x1 = (a + b) / dv
x2 = (a - b) / dv
return 1.0 - (tf.math.abs(Y.cdf(x1) - X.cdf(x1)) + tf.math.abs(Y.cdf(x2) - X.cdf(x2)))```发布于 2021-06-23 21:50:59
你最好看看皮埃尔·雅各布的“excellent series on couplings”。如果我理解正确的话,这里要计算的积分与总变分距离有关。
我在https://colab.research.google.com/gist/brianwa84/2b78eb819ad9cfb910f9a6eb62b4a402/maximal-couplings.ipynb上有一个使用TFP采样最大耦合分布的小演示。
我不知道积分在分析上是否容易处理。
https://stackoverflow.com/questions/68075029
复制相似问题