【问题标题】:Overlapping probability of two normal distribution tfp.distributions.Normal()两个正态分布的重叠概率 tfp.distributions.Normal()
【发布时间】:2021-06-21 21:38:55
【问题描述】:

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

就像里面实现的一样 https://docs.python.org/3.8/library/statistics.html?highlight=normaldist#statistics.NormalDist

【问题讨论】:

    标签: tensorflow tensorflow-probability


    【解决方案1】:

    这是我基于 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)))```
    

    【讨论】:

    • 你可以用中缀/操作符替换tf.math.divide之类的东西; multiply => * 类似。看起来该功能有两个副本。另外,如果你想发送 PR 将overlap_prob 添加到tfp.distributions.Normal,这似乎是合理的。
    【解决方案2】:

    您可能会很好地观看 Pierre Jacob 的 excellent series on couplings。如果我理解正确,您要在此处计算的积分与总变异距离有关。

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

    我不知道积分是否可以解析处理。

    【讨论】: