[Bayes] Point --> Hist: Estimate "π" by R
gt quot by point hist --& Bayes
2023-09-27 14:23:25 时间
Verify the Monte Carlo sampling variability of "π".
p = π/4 与 所得 0.7854 比较接近,故满足 Central Limit theorem。
simulation = function(sampleSize){
c = rep(0,sampleSize)
countIn = 0
for(i in 1:sampleSize){
x = runif(1,-1,1)
y = runif(1,-1,1)
if(sqrt(x*x + y*y) <= 1){
countIn = countIn + 1
}
piHat = countIn / i
c[i] = piHat
}
return(c)
}
pointEstimate = function(testCount){
cc = rep(0,testCount)
for(i in 1:testCount){
sampleSize = 1000
res = simulation(sampleSize)
cc[i] = res[1000]
}
return(cc)
}
testCount = 1000
res = pointEstimate(testCount)
/* 获得很多要构成长条的点 */
hist(res, freq = F, breaks = testCount)
mean(res)
相关文章
- JavaScript--> JavaScript reference--> Statements and declarations--> import
- <input type="file">
- <html>
- <color>数据类型
- JAVA定义栈告警提示:“Stack is a raw type. References to generic type Stack<E> should be parameterized”
- 一则 > ORA-01722: invalid number错误的处理,原因:substr截取的字段中有空格
- jsp注释<%-- --%>和<!-- -->的区别
- English Voice of <<Take A Bow>>
- shell脚本中的"2< " ">&2" "&>"
- [转]JAVA泛型通配符T,E,K,V区别,T以及Class<T>,Class<?>的区别
- 为什么乱码:<meta http-equiv="content-type">前的非ANSI字符
- 屏蔽命令任何输出的:>/dev/null 2>&1
- Vue--路由的基本使用(组件之间的跳转)new VueRouter---配置path和子组件---跳转路径带#<a href="#/register">---显示区域用<router-view>
- 让浏览器不再显示 https 页面中的 http 请求警报<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
- <memory>(包括了auto_ptr,shared_ptr等各种指针)
- HTML <!DOCTYPE> (转自w3school)
- C++基础学习教程(七)----类编写及类的两个特性解析--->多态&继承
- 【Qt程序】基于Qt词典开发系列<十二>呼叫讲述
- python爬虫学习(二):定向爬虫例子-->使用BeautifulSoup爬取"软科中国最好大学排名-生源质量排名2018",并把结果写进txt文件
- What is corresponding Cron expression to fire in every X seconds, where X > 60? --转载
- (原)torch中提示Unwritable object <userdata> at <?>.callback.self.XXX.threads.__gc__
- Address already in use: JVM_Bind<null>:8080错误的解决办法