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

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

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