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)
ProbabilityStatistics的更多相关文章
- 【javascript】:Highcharts实战
PS: Highcharts是一款前端图标设计框架,非常绚. 前端JS: var probabilityStatisticsData; var yearTool; var CoordinateX = ...
随机推荐
- idea修改项目名导致无法找到主类
描述 本地创建项目copy或者是修改项目名和文件夹名称后 启动springboot项目失败 控制台报错 错误无法找到主类 解决办法 1. 求助互联网得知 需要执行 mvn clean install( ...
- day113:MoFang:种植园商城页面&充值集成Alipay完成支付的准备工作
目录 1.种植园商城页面初始化 2.规划商品种类并且构建关于商品的模型类 3.解决APP打包编译之后的跨域限制 4.商品列表后端接口实现 5.前端获取商品列表并显示 6.种植园点击充值允许用户选择充值 ...
- Git设置记住账号密码
Git设置记住账号密码 添加如下配置 [credential] helper = store
- Plugin 插件体系
Solon 的插件也可以叫扩展组件,相当于Spring 的 starter.Solon已经提供了大量的基础插件,但对第三方的框架适配目前较少. 插件 说明 boot插件:: 说明 org.noear: ...
- hadoop3.2+Centos7+5个节点主从模式配置
准备工作: hadoop3.2.0+jdk1.8+centos7+zookeeper3.4.5 以上是我搭建集群使用的基础包 一.环境准备 master1 master2 slave1 slave2 ...
- HTML学习案例-仿慕课网网页制作(一)
概述:仿制慕课网头部导航栏和分支导航栏的外观 考察知识点: 1.消除浮动的原因:如果最上面的块级元素不清楚浮动的话就会影响下面的块级元素的布局 对subnav块使用了float,结果subnav块飞到 ...
- 10. C++对象模型和 this 指针
1. 成员变量和成员函数分开存储 在C++中,类内的成员变量和成员函数分开存储,只有非静态成员变量才属于类的对象上 空对象占用内存空间为:1 ----> C++编译器会给每个空对象也分配一个字节 ...
- C# 9 新特性 —— 补充篇
C# 9 新特性 -- 补充篇 Intro 前面我们分别介绍了一些 C# 9 中的新特性,还有一些我觉得需要了解一下的新特性,写一篇作为补充. Top-Level Statements 在以往的代码里 ...
- Lesson_strange_words4
mount on 安装 arc 弧 actuator 马达,致动器:调节器 roughly 大致,大约 radially 径向,放射状 stepper 步进机 motor 电机,发动机 sequent ...
- EasyUI 表单插件 multiline easyui-textbox 多行换行失效问题
1.问题描述:原始html: <input class="easyui-textbox" name="myname" id="myid" ...