Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. # We'll bootstrap the monk data, consider those to somewhat legit representations of 'real'
  2. # graphs, and run those through the prob calculating function, then compare the prob of our
  3. # random graph to the resulting distribution of probabilities.
  4.  
  5. # we can use the probability of the non bootstrapped, actual Monk graph data to possibly
  6. # slightly change the distribution of the probabitlies, if the bootstrapped calced probs
  7. # seem a bit skewed.
  8.  
  9. # would this have implications regarding the theta involved?
  10.  
  11. # first, we need a random graph.
  12. p = .28
  13. rand.grph <- matrix(sample( c(1, 0), size = 18*18, prob = c(p, (1-p)), replace = TRUE), nrow = 18)
  14.  
  15. theta.mle <- c(-1.9, 1.89, .098)
  16. acc.trials.kappa = 700
  17. burn = 300
  18.  
  19.  
  20. prob.of.graph = function(graph.test, theta.mle, acc.trials.kappa, burn){
  21. kappa.test <- mean(mcmc.kappa(graph, theta = theta.mle,
  22. acc.trials = acc.trials.kappa)$kappa[burn:(acc.trials.kappa-1)])
  23. return(exp( Theta.vector %*% c(g1(graph.test), g2(graph.test), g3(graph.test)) / kappa.test))
  24. }
  25.  
  26. # now, we want to retain certain charecteristics of the monk graph, so we wont randomly select
  27. # cells from the graph. We could do rows, we could to columns, the idea is to be random and
  28. # different while still keeping certain info from the graph, that is specifically different
  29. # than only the total number of ones in the graph.
  30.  
  31. # we'll chose some by column, some by rown, and some by mixing up different grids, mxn, from
  32. # the monk graph
  33. bootsrap.graph = function(graph){
  34. r.comp <- runif(1)
  35. if(r.comp < .34){
  36. smp <- sample(1:18, size = 18, replace = TRUE)
  37. graph.new <- graph[,smp]}
  38. else #(r.comp < .67)
  39. {
  40. smp <- sample(1:18, size = 18, replace = TRUE)
  41. graph.new <- graph[,smp]}
  42. # else{
  43. # smp.col <- sample(2:17, size = 1, replace = TRUE)
  44. # smp.row <- sample(2:17, size = 1, replace = TRUE)
  45. # graph.new <- as.matrix(rbind( cbind( graph[smp.row:18,1:smp.col], graph[smp.row:18,(smp.col+1):18]),
  46. # cbind( graph[1:(smp.row-1),smp.col:18], graph[1:(smp.row-1),1:(smp.col-1)]) ),
  47. # nrow = 18)
  48. # colnames(graph.new) <- colnames(graph)
  49. # rownames(graph.new) <- rownames(1:18)
  50. # }
  51.  
  52. return(graph.new)
  53. }
  54.  
  55. # Yup, we're staying
  56. View(bootsrap.graph(graph))
  57.  
  58.  
  59. prob.dist.func = function(iter, graph.initial, theta.mle, acc.trials.kappa, burn){
  60. prob.store <- rep(0, iter)
  61. for(i in 1:iter){
  62. graph.test <- bootsrap.graph(graph.initial)
  63. prob.store <- prob.of.graph(graph.test, theta.mle, acc.trials.kappa, burn)
  64. }
  65. return(prob.store)
  66. }
  67.  
  68. prob.dist.func = function(iter, graph.initial, theta.mle, acc.trials.kappa, burn){
  69. prob.store <- rep(0, iter)
  70. for(i in 1:iter){
  71. graph.test <- bootsrap.graph(graph.initial)
  72. prob.store [i] <- prob.of.graph(graph.test, theta.mle, acc.trials.kappa, burn)
  73. }
  74. return(prob.store)
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement