三国杀国战吧 关注:91,234贴子:2,493,520
  • 5回复贴,共1

【理性分析3.1】周泰不屈实验/理论概率模型实验源码

只看楼主收藏回复

感觉写完了这个帖子,我变成了周泰黑


IP属地:上海1楼2019-12-31 11:19回复
    除非源码出现问题,请勿回复
    对于不屈的分析,帖子在这里:
    https://tieba.baidu.com/p/6418940497
    This code is under MIT lisence. Please cite author's name (Hedonist55) when reference the code.
    不屈实验源码 (peach --> 桃的数量,trial ---> 实验次数,返回一个数组每个数表示在某次实验周泰在第几张屈死掉的)
    indomitability.experiment <- function(peach, trial) {
    deck <- rep(1:13, each=8)
    result <- 1:trial
    for (i in 1:trial) {
    experiment.count <- rep(FALSE, 13)
    deck.shuffle <- sample(deck)
    end <- FALSE
    index <- 1
    peach.used <- 0
    while (!end) {
    point <- deck.shuffle[index]
    if(!experiment.count[point]) {
    experiment.count[point] <- TRUE
    index <- index + 1
    } else {
    if(peach.used == peach) {
    end <- TRUE
    } else {
    peach.used <- peach.used + 1
    index <- index + 1
    }
    }
    }
    result[i] <- index
    }
    return(result)
    }


    IP属地:上海3楼2019-12-31 11:22
    回复
      理论模型计算源码:
      叫emprical就好,peach指的是桃的数量(0到7之间)
      conditional.prob <- function(x, y) {
      result <- 0
      for (i in 1:(x - 1 - y)) {
      part.log <- log(choose(x - 1 - y, i)) + log(choose(8 * i, x - 1)) - log(choose(104, x - 1))
      part <- exp(part.log) * ((-1) ^ (x - 1 - y - i))
      result <- result + part
      }
      return(result)
      }
      emprical <- function(peach) {
      result <- 1:13
      sample.space <- (peach + 2):(peach + 14)
      for (i in 1:13) {
      card <- sample.space[i]
      cur <- conditional.prob(card, peach) * choose(13, card - peach - 1)
      cur <- cur * (8 * (card - peach - 1) - (card - 1)) / (104 - (card - 1))
      result[i] <- cur
      }
      names(result) <- sample.space
      return(result)
      }


      IP属地:上海4楼2019-12-31 11:24
      回复
        这个是R码,需要下载R才能正确食用。


        IP属地:上海5楼2019-12-31 11:26
        回复
          R语言?


          来自Android客户端6楼2019-12-31 14:34
          回复