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)
  • 相关阅读:
    IOS的系统手机 宽度无法自适应 解决办法
    iframe 设置背景透明
    thinkphp5 常用的2个方法
    thinkphp引入后台模板文件的路径怎么写?
    html的confirm()
    php 如何往数组里添加数据
    thinkphp51 重定向 redirect()
    【Oracle 触发器】(4)触发器应用场景--数据的确认
    【Oracle 触发器】(3)触发器应用场景--复杂的安全性检查
    【Oracle 触发器】(2)触发器的分类(语句级/行级)
  • 原文地址:https://www.cnblogs.com/rsapaper/p/13531655.html
Copyright © 2011-2022 走看看