DS from scratch CH6

  • math.erf是 Error Function,主要和正态分布的CDF有关,正态分布的CDF是个积分,且不能被简化。
  • 这种方法叫Binary Search
#通过累计概率来求正态分布分布中的值
def inverse_normal_cdf(p, mu=0, sigma=1, tolerance=0.00001):
    """find approximate inverse using binary search"""

    # if not standard, compute standard and rescale
    if mu != 0 or sigma != 1:
        return mu + sigma * inverse_normal_cdf(p, tolerance=tolerance)
    
    low_z, low_p = -10.0, 0            # normal_cdf(-10) is (very close to) 0
    hi_z,  hi_p  =  10.0, 1            # normal_cdf(10)  is (very close to) 1
    while hi_z - low_z > tolerance:
        mid_z = (low_z + hi_z) / 2     # consider the midpoint
        mid_p = normal_cdf(mid_z)      # and the cdf's value there
        if mid_p < p:
            # midpoint is still too low, search above it
            low_z, low_p = mid_z, mid_p
        elif mid_p > p:
            # midpoint is still too high, search below it
            hi_z, hi_p = mid_z, mid_p
        else:
            break

    return mid_z
  • 伯努利实验是结果只有0和1的实验,1的概率为P
  • Binomial是重复N次的Bernoulli Trial
  • 二项式分布的std dev是怎么算出来的?
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 背景 一年多以前我在知乎上答了有关LeetCode的问题, 分享了一些自己做题目的经验。 张土汪:刷leetcod...
    土汪阅读 14,349评论 0 33
  • 前言 在大多数现实情况下,模型可以简化并通过模型对显式进行探索,本章可以学到的东西 数据分析中使用基础模型 使用积...
    欧呆哈哈哈阅读 10,218评论 0 2
  • 随机变量是根据偶然性取值的变量。我们在谈到随机变量时,通常是以“概率分布”的形式来描述他们。也即:随机变量落在每一...
    小狸投资阅读 10,905评论 1 7
  • 开篇便是玛丽琳的女儿去世了,有点像推理小说,徐徐道来,女儿为什么失踪,为什么会自杀,这一切似乎和她们的家庭环境脱...
    方稀宋阅读 1,462评论 0 0
  • 场景描写 已经处署了,南方的树木都还郁郁葱葱,街上的行人仍然是短裙背心裤衩,半点没有要入冬的迹象。 ...
    尘亦尘阅读 1,059评论 0 0