我遇到了有关Barabasi-Albert Network的作业问题。问题要求:
我知道Barabasi-Albert网络的幂律指数应该通过仿真为3,但我无法通过使用以下代码来得到答案:
library(igraph)
ba <- barabasi.game(1000, m=5) #Simulate a barabasi game with 1000 nodes and m=5
k <- as.vector(igraph::degree(ba)) #Assign k as the degree vector
min(k) #Maximum likelihood estimator of K
f <- function(k0) { #MLE of γ
a = k/(k+k0)
b = log(k0/(k+k0))
return(1 - 1/mean(b) - 1/mean(a))
}
str(root <- uniroot(f, c(min(k), max(k)), tol = 0.0001)) #Find the root of γ
f4 <- function(gamma) { #Log-likelihood Function
k0 <- root$root
n <- length(k)
return(n*log(gamma-1)+n*(gamma-1)*log(k0)-gamma*sum(log(k+k0)))
}
str(root2 <- uniroot(f4, c(1.0, 5.0), tol = 0.0001))
我希望γ应该接近3,但我无法得到答案。请问是否有人知道问题出在哪里?非常感谢。