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

  In the article thoughts on language design 2007 steele

in the article thoughts on language design 2007 steele suggests that structured programming techniques may not be

  Design the logic for application for company

Design logic for an application for company which wants a report containing a breakdown of payroll by department. Input includes each employee's last name, first name, department number.

  Design a c# windows phone 8 application

Design and implement a C# Windows Phone 8 application based on the SoundBoard app in the Windows Phone 8 Development for Absolute Beginners textbook.

  Find out the total of balances

Display all the contents of the file in a tabular format with the first row being a header row and write to a file that is called account numbers.txt only the account numbers from the read file.

  What is the difference between the two statements

What is the difference between the following two statements?

  Analysis of a group of weight measurements

Prepare a program that takes an input weight and puts the correct value - An analysis of a group of weight measurements involves converting a weight value into an integer category number that is determined as given:

  Design a flowchart that is also a fully functional program

Using Visual Logic, design a flowchart that is also a fully functional program. According to your design, the program must: Continually accept data regarding the purchase of fruit until a sentinel value is entered.

  Give a pseudo-code description

Give a pseudo-code description of the o(n)- time algorithm for computing the power function P(x,n). Also draw the recursion trace of this algorithm for computation of p(2,5)

  Use the watchdog in its default position

Use the watchdog in its default position (must be petted in less than 32 ms). Generate a 275 Hz, 50% duty cycle on P9.7. Use a timer with the SMCLK.

  Recursive method to search a string for a byrd

Write a recursive method that searches a string for a Byrd. A Byrd has the following properties. Its first character is an 'A'. If it is a two character Byrd then its second and last character is an 'H'.

  How might the fetch phase of the von neumann cycle

How might the fetch phase of the Von Neumann cycle have to be changed from what was described in the text?

  Calculates and displays the property tax

Write a java application that calculates and displays the property tax for N property owners. N should be declared as a constant and it should be equal to the largest digit of your student ID number

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