igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

## [igraph] How to avoid indexing issues with "which" fuction

 From: giorgio delzeri Subject: [igraph] How to avoid indexing issues with "which" fuction Date: Wed, 31 May 2017 22:42:50 +0200

Hi, I already wrote part of the igraph algorithm which should do this (it is a simulation of a contagion process, but in a positive sense: innovation spreading)

It starts from a scale-free graph.
It randomly select a given percentage (10%) of the whole vertices ad assign them the label (or "compartment") IMMUNE.
The rest of vertices are, instead, IGNORANT.
It randomly select 1 node among the IGNORANT ones, and changes its label in "SPREADER". (so far its all ok with the algorithm, I think).

Now, it starts a while cycle (the cycle stops if there are no more vertices "IGNORANT" and/or there are no more vertices "SPREADER").
It select a given percentage (for example 15%) of the "IGNORANT" nodes that are adjacent to "SPREADER" , and changes their label (compartment) from "IGNORANT" to "SPREADER" (this is the innovation spreading).
It select a given percentage (for example 12%) of the nodes that are "SPREADER" (the whole "SPREADER" compartment, not only the ones that are JUST become "SPREADER") and change their label to "STIFLER" (stiflers are the nodes that were spreader of the innovation, and now they stop spreading).
(END OF THE WHILE CYCLE).

END OF THE ALGORITHM.

nb: note that the "IMMUNE" nodes rest in the same compartment (same label) during the whole process.

Below, the first "edition" of my algorithm:

"
g <- sample_pa(n=100, power=1, m=1, directed= F)

V(g)\$compartment <- “IGNORANT”

x <- sample(vcount(g), round(vcount(g)*0.1))

V(g)[x]\$compartment <- “IMMUNI”

y <- sample(which(V(g)\$compartment==”IGNORANT”), 1)

V(g)[y]\$compartment <- “SPREADER”

p <- 0.15

r <- 0.12

while (sum(V(g)\$compartment==”SPREADER”) >0) {

w <- unique(unlist(adjacent_vertices(g, which(V(g)\$compartment==”SPREADER”))))

z <- sample(which(V(g)[w]\$compartment==”IGNORANT”), ceiling(p*sum(V(g)[w]\$compartment==”IGNORANT”)))

V(g)[z]\$compartment <- “SPREADER”

k <- sample(which(V(g)\$compartment==”SPREADER”), ceiling(r*sum(V(g)\$compartment==”SPREADER”)))

V(g)[k]\$compartment <- “STIFLER”

}.

"
A friend advised me to change from the first version to the version just below:

"
g <- sample_pa(n=100, power=1, m=1, directed= F)

V(g)\$compartment <- "IGNORANT"
x <- sample(vcount(g), round(vcount(g)*0.1))
V(g)[x]\$compartment <- "IMMUNI"
y <- sample(which(V(g)\$compartment=="IGNORANT"), 1)
V(g)[y]\$compartment <- "SPREADER"
degree(g,which(V(g)\$compartment=="SPREADER"))
p <- 0.15
r <- 0.12

while (sum(V(g)\$compartment=="SPREADER") >0) {

w <- unique(unlist(adjacent_vertices(g, which(V(g)\$compartment=="SPREADER"))))
dummy_1 <- which(V(g)[w]\$compartment=="IGNORANT")
z <- sample(w[dummy_1], ceiling(p*length(dummy_1)))
V(g)[z]\$compartment <- "SPREADER"

dummy_2 <- which(V(g)\$compartment=="SPREADER")
k <- sample(dummy_2, ceiling(r*length(dummy_2)))
V(g)[k]\$compartment <- "STIFLER"
}
"

I have 3 problem I can't solve:
1) The while cycle, and the algorithm, must stops if there are no more nodes in the "IGNORANT" compartment and/or there are no more nodes in the "SPREADER" compartment.
2) I already tried the algorithm, and the number of the nodes that are "IMMUNE", decreases after a certain number of the while cycle. But that vertices must remain in the same compartment during the whole process!
Maybe an issue in the while cycle, i think the problem is the indexing of nodes when it chooses the vertices to change from "IGNORANT" to "SPREADER", and/or the ones to change from "SPREADER" to "STIFLER".
3) I have to revise the algorithm, because I want to obtain, at the and of the process, a print of a matrix that tell me about the number of "IGNORANT", "SPREADER" and "STIFLER" nodes in EACH iteration of the while cycle.

Does anyone know the way to solve these 3 problems?
Thank you in advance!!

Giorgio

reply via email to

 [Prev in Thread] Current Thread [Next in Thread]
• [igraph] How to avoid indexing issues with "which" fuction, giorgio delzeri <=