4月 03

R与分形

1.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
plot.tri <- function(n = 1000, col ="blue", ani=FALSE, cex=1.2){
    p <- runif(n);
    X <- rbind(rep(0, n), rep(0, n))
    B <- cbind(c(0,0),c(0.25,0.433),c(0.5,0))
    if(ani) plot(0,0,xlim=c(0,1),ylim=c(0,0.85),type="n",xlab="",ylab="")
    for(i in 2:n){
        pp <- p[i];
        ind <- rank(c(c(1/3,2/3,1), pp), ties.method="min")[4]
        X[,i] <- 0.5*X[,i-1] + B[,ind]
        if(ani) points(X[1,i], X[2,i],pch = ".", cex = 1, col = col)
    }
    if(!ani) plot(X[1,], X[2,],pch = ".", cex = cex, col = col, xlab="", ylab="")
}
plot.tri(100000, ani=TRUE)

sanjiao
Continue reading

4月 01

Benford law(本福特定律)

  1. 定义

  2. 本福特定律,也称为本福德法则,说明一堆从实际生活得出的数据中,以1为首位数字的数的出现机率约为总数的三成,接近期望值1/9的3倍。推广来说,越大的数,以它为首几位的数出现的机率就越低。它可用于检查各种数据是否有造假。

  3. 解释

  4. 一组平均增长的数据开始时,增长得较慢,由最初的数字a增长到另一个数字a + 1起首的数的时间,必然比a + 1起首的数增长到a + 2,需要更多时间,所以出现率就更高了。
    从数数目来说,顺序从1开始数,1,2,3,…,9,从这点终结的话,所有数起首的机会似乎相同,但9之后的两位数10至19,以1起首的数又大大抛离了其他数了。而下一堆9起首的数出现之前,必然会经过一堆以2,3,4,…,8起首的数。若果这样数法有个终结点,以1起首的数的出现率一般都比9大。
    Continue reading