Compare using link labeles method

Assignment Help Programming Languages
Reference no: EM131076098

Experiment

library(igraph)

Just to make labels and scores for original graph and its done once for the comparison reasons

G.O<- read.graph("dolphins.gml",format = c("gml")) G.O is the original graph "network"

ResourceAllocationFunction <- matrix(0, nrow = length(V(G.O)), ncol = length(V(G.O)))

source('ResourceAllocation Function.R')

for(i in 1:length(V(G.O))){
for(j in 1:length(V(G.O))){

ResourceAllocationFunction[i,j] <-Resource.Allocation(G.O,i,j)

}
}

Create an edgelist

G.O.Simplfied <- simplify(G.O, remove.multiple = T, remove.loops = T )

G.O.edgeList <- get.edgelist(G.O.Simplfied)

N <- length(V(G.O)) #number of nodes for original graph

L <- nrow(G.O.edgeList) #number of links..original graph num.of.allpossibleLinks <- N *(N-1)/2

ScoresOfexistent.G.O <- NULL

for(i in 1:(N-1)) {
for(j in (i+1):N) { if(i>j)
{temp <- j j <- i
i<- temp}
l <- (i-1)*N-i*(1+i)/2 + j #l is the link label

if(G.O[i,j]==1){
ScoresOfexistent.G.O <- rbind(ScoresOfexistent.G.O,c(l, ResourceAllocationFunction [i,j],i,j))
}
}
}
GO.Labels <- NULL #for original graph
GO.Labels <- c(GO.Labels ,ScoresOfexistent.G.O[,1])#original

Select randomly 10% of the links, without repetitions

num <- round(0.1* NROW(G.O.edgeList))

MySeq <-seq(from=1 , to=length(G.O.edgeList)/2)

p <- NULL

Labes.ScoresExp2 <- list() #for thr Gr

ScoresOfNonexistentExp2 <- list() GTopNList <- list()

for(x in 1:1000){
#1-
Lc <- 0 #for jaccrd

Mysample <- NULL
Mysample <- sample(MySeq,num,replace =FALSE)

GraphSample <- MySeq[- Mysample] #the same as the original edgelist but with 10% of the links removed but its not an edgelist its integer (but its only a sequence of numbers)
res <- NULL
for(i in 1:length(GraphSample)){
res<-rbind(res, G.O.edgeList[GraphSample[i],])}
GR <- graph.edgelist(res,directed=FALSE)#the same as GraphSample but converted into a graph

#GR.Simplified <- simplify(GR, remove.multiple = T, remove.loops = T )
#GR.edgelist <- get.edgelist(GR.Simplified)

#2- Get the GR scores#################################################

GR.Scores<- matrix(0, nrow = length(V(GR)), ncol = length(V(GR))) for(i in 1:N){

for(j in 1:N){

GR.Scores[i,j] <- Resource.Allocation(GR,i,j) #scores for the removed graph GR that has 10% of links removed.

}
}

#3- refine the Removed graph to take only edges that don't exist (missing and nonexistent) with there link labels############

ScoresOfNonexistent <- NULL

for(i in 1:(N-1)) {
for(j in (i+1):N) {

if(i>j)
{temp <- j j <- i
i<- temp}
l <- (i-1)*N-i*(1+i)/2 + j

if(GR[i,j]== 0){
ScoresOfNonexistent <- rbind(ScoresOfNonexistent,c(l,GR.Scores[i,j]))
}
}
}

#4-sort or order the GR scores only for links that don't exist o.J<-NULL

o.J <- order(ScoresOfNonexistent[ , 2] , decreasing=TRUE)

ScoresOfNonexistent <- ScoresOfNonexistent[o.J,]###ordered scores

#4-take the top N scores and add them to GR (N is 10% of the existing links = num)

Labels.Of.GTopN <- NULL for(a in 1:num){

Labels.Of.GTopN <- rbind( Labels.Of.GTopN,ScoresOfNonexistent[a,])

}

#5- compare using link labeles method##############################################

GTopNLabels <- NULL comparison <- NULL

GTopNLabels <- c(GTopNLabels,Labels.Of.GTopN[,1]) comparison <- GTopNLabels %in% GO.Labels
Lc<- length(comparison[comparison==TRUE]) #number of top scored links that were predicted correctly

pr <- Lc/num #compute precision
p <-c(p,pr) #vector <- c(vector, v) vector of precesion for each iteration

}#end of for loop

histinfo.p <- hist(p,main="Histogram of precision in experiment 2 using Resource Allocation scores/Dolphins ",xlab="precision",border="blue", col="grey",xlim=c(0,1),las=1,breaks=5,prob =TRUE)

hist(p,main="Histogram of precision in experiment 2 using Resource Allocation scores",xlab="precision",border="blue", col="grey",xlim=c(0,1),breaks=5)

RandomScore <- function(g,i,j){

RandomScoreFunction <- runif(1,min = 0, max = 1)

RandomScoreFunction

}

Reference no: EM131076098

Questions Cloud

Describe pseudo code algorithms for insertion into : Describe pseudo code algorithms for insertion into and removal from an ADT dictionary implemented with an index fi le organized as a B-tree.
Main factors that organisations consider prior : What are the two main factors that organisations consider prior to making a decision to outsource their activities partially or fully?
Program and version of the program : Write instructions for a 1- to 2-page handout that explains how to create a table in Microsoft® Word (whatever version you have) and how to add and delete columns and rows from an existing table.
List the calls to the various functions : List the calls to the various functions in the order in which they occur.
Compare using link labeles method : Just to make labels and scores for original graph and its done once for the comparison reasons - refine the Removed graph to take only edges that don't exist (missing and nonexistent) with there link labels
Basic components required to set up a network : What are the basic components required to set up a network? How do you add a PC to a network?
Discuss the concept of reintegrative shaming : Due to the fact that informal methods of social control are often more effective than legal sanctions in curbing deviant behavior, discuss the concept of reintegrative shaming and how it might be used in a more formal legal system such as that fou..
What is the maximum number of records that can be stored : What is the maximum number of records that can be stored?
Role of information security policy : Using the paper in Weeks 2 and 3 add an additional 3-to 4-pages describing the importance of policies and standards for maintaining information systems security.

Reviews

Write a Review

 

Programming Languages Questions & Answers

  Develop the payroll program to enter two double values

Develop the payroll program named CalcPay which permits the user to enter two double values namely hours worked and hourly rate.

  Explain post-conditions and description of the parameters

Write specifications for method which advances any given date by one day. Write a statement of purpose, pre- and post-conditions, and description of the parameters.

  Calculate the minimum salary for all employees.

Calculate the minimum salaries for exempt and non-exempt employees.

  Allows the user to enter the cost for an item

Write a program that allows the user to enter the cost for an item and the number of that item ordered.

  Why is lisp dominating the artificial intelligence

What is the difference between functional and imperative programming language?

  Create method to generate random integers

Create a method named posNeg which generates 1000 random integers. Range of numbers must be from -5 to +5 inclusive.

  Program to prompt the user for an arithmetic choice

The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculator program.

  Explain the loops in detail

Even should only be reading for the FOR Loop. I tried moving it around and it won't work so I don't know how to fix it to not show on the DO..WHILE Loop and the WHILE Loop

  Write a c function called values that returns void

Write a C function called values that returns void and takes two double precision arguments (called a and b) and one double precision array argument.

  Construct a diagram using rationaleto map the arguments

Construct a diagram using Rationaleto map the arguments about a moral claim that you have identified in the article/case study

  Recursive double function

each of these returns the list consisting of each element of list y in a list has been replaced by two copies of the elements and

  Diagnostic file thatanalyzes syntax in sas file a line

Diagnostic file thatanalyzes syntax in SAS file a line at a time

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd