R/tests/acceptance_prob_test.R

Defines functions acceptance_prob_test prior

#This script tests that the new acceptance prob gives the same as the old one:
library(Blolog)
library(statnet)
library(lolog)
library(coda)
library(doParallel)
library(ggplot2)

setwd("C:/Users/Duncan/Documents/Academics/UCLA_Academics/Networks/LOLOG_Cateloging/1_9_UniversityEmails")
load("processed_data.RData")

n <- get.network.attribute(net,"n")
e <- choose(n,2)

formula_rhs <- "edges+triangles+star(c(2,3))"
prior = function(theta){1}
theta_0 = c(-2,0.1,0.1,0.1)
theta_1 = c(0,0,0,0)

acceptance_prob_function_1 <- acceptance_prob
acceptance_prob_function_2 <- acceptance_prob_cpp
  
acceptance_prob_test <- function(acceptance_prob_function_1,acceptance_prob_function_2,times = 10){
  
  s <- sample(1:e,e)
  acceptance_prob_1 <- acceptance_prob_function_1(s,theta_0,theta_1,prior,net,formula_rhs)
  acceptance_prob_2 <- acceptance_prob_function_2(s,theta_0,theta_1,prior,net,formula_rhs)
  
  #same = ((acceptance_prob_1 - acceptance_prob_2) < 10**(-5))
  
  #if(same){
    #print("Both functions return the same change stats")
  #}
  
  t_1 <- microbenchmark(acceptance_prob_1 <- acceptance_prob_function_1(s,theta_0,theta_1,prior,net,formula_rhs),times = times)
  t_2 <- microbenchmark(acceptance_prob_2 <- acceptance_prob_function_2(s,theta_0,theta_1,prior,net,formula_rhs),times = times)
  
  print(paste("Method 2 is ",summary(t_1)$mean/summary(t_2)$mean, " times faster than method 1",sep=""))
  return()
}

acceptance_prob_test(acceptance_prob,acceptance_prob_cpp,times = 20)
duncan-clark/Blolog documentation built on June 22, 2022, 7:57 a.m.