首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >两个正态分布tfp.distributions.Normal()的重叠概率

两个正态分布tfp.distributions.Normal()的重叠概率
EN

Stack Overflow用户
提问于 2021-06-22 05:38:56
回答 2查看 66关注 0票数 0

如何计算两个tfp.distributions.Normal的重叠概率?

类似于在https://docs.python.org/3.8/library/statistics.html?highlight=normaldist#statistics.NormalDist中实现的方法

EN

回答 2

Stack Overflow用户

发布于 2021-06-22 19:04:25

下面是我基于statistics.NormalDiststatistics.NormalDist代码的实现:

代码语言:javascript
复制
    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)))```
票数 2
EN

Stack Overflow用户

发布于 2021-06-23 21:50:59

你最好看看皮埃尔·雅各布的“excellent series on couplings”。如果我理解正确的话,这里要计算的积分与总变分距离有关。

我在https://colab.research.google.com/gist/brianwa84/2b78eb819ad9cfb910f9a6eb62b4a402/maximal-couplings.ipynb上有一个使用TFP采样最大耦合分布的小演示。

我不知道积分在分析上是否容易处理。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68075029

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档