Cleanup of main. Adding Katz
This commit is contained in:
parent
1dc4055959
commit
f30cb8cd21
@ -4,14 +4,8 @@
|
||||
# Noah L. Schrick - 1492657
|
||||
|
||||
library(igraph)
|
||||
library(sna)
|
||||
library(Rgraphviz) # Reading graphviz' "dot" files
|
||||
library(readr)
|
||||
|
||||
################# Read in the previously generated networks #################
|
||||
# If sourcing:
|
||||
#setwd(getSrcDirectory()[1])
|
||||
# If running:
|
||||
################## Read in the previously generated networks ##################
|
||||
setwd(dirname(rstudioapi::getActiveDocumentContext()$path))
|
||||
source("./CG_Files/manual_import.R")
|
||||
|
||||
@ -19,6 +13,11 @@ car <- import_networks(1)
|
||||
hipaa <- import_networks(2)
|
||||
pci <- import_networks(3)
|
||||
|
||||
car.deg <- degree(car)
|
||||
hipaa.deg <- degree(hipaa)
|
||||
pci.deg <- degree(pci)
|
||||
################################ Centralities ################################
|
||||
source("centralities.R")
|
||||
|
||||
#### Katz
|
||||
car.katz <- katz.cent(car)
|
||||
hipaa.katz <- katz.cent(hipaa)
|
||||
pci.katz <- katz.cent(pci)
|
||||
|
||||
|
||||
21
centralities.R
Normal file
21
centralities.R
Normal file
@ -0,0 +1,21 @@
|
||||
katz.cent <- function(A, alpha=NULL, beta=NULL){ #NULL sets the default value
|
||||
if (class(A) == 'igraph'){
|
||||
#Error checking. Turn into adj matrix.
|
||||
A <- get.adjacency(A)
|
||||
}
|
||||
|
||||
lam.dom <- eigen(A)$values[1] #dom eigenvec
|
||||
if (is.null(alpha)){
|
||||
alpha <- 0.9 * (1/lam.dom) #Set alpha to 90% of max allowed
|
||||
}
|
||||
|
||||
n <- nrow(A)
|
||||
if (is.null(beta)){
|
||||
beta <- matrix(rep(1/n, n),ncol=1)
|
||||
}
|
||||
|
||||
#Katz scores
|
||||
scores <- solve(diag(n) - alpha*A,beta)
|
||||
|
||||
return(scores)
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user