spread.hits: Spread hits over a network

Description Usage Arguments Examples

Description

Spread hits over a network

Usage

1
spread.hits(g, h = 10, lambda = 1, distmethod = "shortest.paths", start.node = NULL, hitColor = "red", D = NULL,binary=TRUE)

Arguments

g
h
lambda
distmethod
start.node
hitColor
D
binary

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
1+1

## The function is currently defined as
function (g, h = 10, lambda = 1, distmethod = "shortest.paths", 
    start.node = NULL, hitColor = "red", D = NULL) 
{
    if (class(g) != "igraph") 
        stop("Input 'g' is not a graph: Stop feeding me crap!")
    if (is.null(V(g)$hits)) 
        V(g)$hits <- 0
    if (is.null(V(g)$color)) 
        V(g)$color <- "grey"
    if (is.null(start.node)) 
        start.node <- sample(as.character(V(g)[hits == 0]), 1)
    if (is.null(D)) 
        D <- dist.graph(g, method = distmethod)
    prob <- lambda * exp(-lambda * D[start.node, ])
    prob[start.node] <- 0
    if (sum(prob) > 0 && sum(prob > 0) < h) 
        prob[prob == 0] <- min(prob[prob != 0])
    if (sum(prob) > 0) 
        prob <- prob/sum(prob)
    else prob <- rep(1, length(prob))/length(prob)
    sampled <- c(start.node, sample(as.character(V(g)), size = h - 
        1, prob = prob))
    sampled <- as.numeric(sampled)
    V(g)[sampled]$hits <- 1
    V(g)[sampled]$color <- hitColor
    return(g)
  }

nea documentation built on May 2, 2019, 5:52 p.m.