Skip to content

Instantly share code, notes, and snippets.

@ayota
Created March 29, 2015 18:25
Show Gist options
  • Save ayota/0bfa8ebe18c78249c3e2 to your computer and use it in GitHub Desktop.
Save ayota/0bfa8ebe18c78249c3e2 to your computer and use it in GitHub Desktop.
new power function
power <- function(B1 = B1, B2 = B2, v.old = v, tol = 10^-10, p = .15) {
N <- length(v)
B.p <- matrix(0, ncol=5242, nrow=5242)
B.p <- sapply(1:5242, function(x) (1-p)/sum(B1[x,]) * B1[x,])
v.old <- v
v.new <- B.p %*% v.old + (p/N) * B2 %*% v.old
v.new <- v.new / norm(v.new)
i <- 0
while( norm(v.new - v.old) > tol) {
v.old <- v.new
v.new <- B.p %*% v.old + (p/N) * B2 %*% v.old
v.new <- v.new / norm(v.new)
i <- i + 1
}
return(list(vector = v.new,
value = t(v.new) %*% (B.p + (p/N) * B2) %*% v.new,
topnode = which.max(v.new),
iter = i
))
}
##results
$vector
huge vector of nonsense
$value
[,1]
[1,] 1
$topnode
[1] 2775
$iter
[1] 132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment