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)
  • 相关阅读:
    AC自动机+全概率+记忆化DP UVA 11468 Substring
    java POI技术之导出数据优化(15万条数据1分多钟)
    验证IP端与数据库Ip端是否重复!!!
    JAVA中IP和整数相互转化(含有掩码的计算)
    Nginx搭建反向代理服务器过程详解
    session原理及实现共享
    Linux部署多个tomcat
    linux下怎么修改mysql的字符集编码
    linux yum 安装mysql
    VM虚拟机下的Linux不能上网
  • 原文地址:https://www.cnblogs.com/rsapaper/p/13531655.html
Copyright © 2011-2022 走看看