zoukankan      html  css  js  c++  java
  • ProbabilityStatistics


    class ProbabilityStatistics:

    @staticmethod
    def simulation_of_probability(v, ratio=10000):
    assert v >= 0 and v <= 1
    _v = int(v * ratio)
    complement = ratio - _v
    l = [0 for _ in range(_v)] + [1 for _ in range(complement)]
    import random
    # TODO numpy scipy
    return random.choice(l) == 0


    if __name__ == '__main__':
    vs = (0.1, 0.5, 0.5123, 0.9)
    for v in vs:
    for times in (100, 1000, 10000, 100000):
    ok = 0
    for i in range(times):
    b = ProbabilityStatistics.simulation_of_probability(v)
    if b:
    ok += 1
    print('got-times,run-times,p,target', ok, times, ok / times, v)

    got-times,run-times,p,target 14 100 0.14 0.1

    got-times,run-times,p,target 83 1000 0.083 0.1

    got-times,run-times,p,target 957 10000 0.0957 0.1

    got-times,run-times,p,target 10171 100000 0.10171 0.1

    got-times,run-times,p,target 42 100 0.42 0.5

    got-times,run-times,p,target 524 1000 0.524 0.5

    got-times,run-times,p,target 4940 10000 0.494 0.5

    got-times,run-times,p,target 50071 100000 0.50071 0.5

    got-times,run-times,p,target 55 100 0.55 0.5123

    got-times,run-times,p,target 475 1000 0.475 0.5123

    got-times,run-times,p,target 5205 10000 0.5205 0.5123

    got-times,run-times,p,target 51188 100000 0.51188 0.5123

    got-times,run-times,p,target 92 100 0.92 0.9

    got-times,run-times,p,target 902 1000 0.902 0.9

    got-times,run-times,p,target 9035 10000 0.9035 0.9

    got-times,run-times,p,target 90093 100000 0.90093 0.9


    class ProbabilityStatistics:

    @staticmethod
    def simulation_of_probability(v, ratio=10000):
    assert v >= 0 and v <= 1
    _v = int(v * ratio)
    complement = ratio - _v
    l = [0 for _ in range(_v)] + [1 for _ in range(complement)]
    import random
    # TODO numpy scipy
    return random.choice(l) == 0


    if __name__ == '__main__':
    vs = (0.1, 0.5, 0.5123, 0.9)
    for v in vs:
    for times in (100, 1000, 10000, 100000):
    ok = 0
    for i in range(times):
    b = ProbabilityStatistics.simulation_of_probability(v)
    if b:
    ok += 1
    print('got-times,run-times,p,target', ok, times, ok / times, v)
  • 相关阅读:
    sass的安装
    git上传项目到github教程
    v-if 和v-show的区别
    es5实现数组去重
    原生js实现选中所有的checkbox
    拨打手机号
    H5页面打开小程序
    h5 网页 直接唤起淘宝app,并跳转到对应商品页面
    webstorm配置git
    elementUi 日历添加可选区间(只能选择一个月的时间段)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/13531655.html
Copyright © 2011-2022 走看看