Ok, I think I wrote a too long email ;-) So I'll try to simplify my request:
I have a problem with the "wich" and/or "adjacent_vertices" functions. I think there is a problem about the ids-indexing. In the part of the algorithm just below: " w <- unique(unlist(adjacent_vertices(g, which(V(g)$compartment=="SPREA DER")))) 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" " it should randommly select one of the adjacent vertices of "SPREADER" vertices that are "IGNORANT" (IGNORANT and SPREADER, such as IMMUNE and STIFLER are all "label" that I assigned to the vertices) and change their label in "SPREADER". Then, it select a certain percentage of the "SPREADER" and changes their label in "STIFLER". But there are some indexing issues with that part of the algorithm, because at the end of the process, I found that some of the nodes that were "IMMUNE" at the start of the algorithm (at the beginning of the algorithm, I select a certain percentage of the whole nodes and I call them "IMMUNE", but these nodes have to remain "IMMUNE" during the whole process!!) changes their label in "SPREADER". So I think the problem is in the fact that these functions "confuse" the ids of vertices with the position in the "adjacent_vertices" vector. Am I wrong? How can I solve this problem with the algorithm, do you have any idea or advice? Thanks in advance. Giorgio 2017-05-31 22:42 GMT+02:00 giorgio delzeri <[email protected]>: > 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==”SPREA > DER”)))) > > 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=="SPREA > DER")))) > 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 > >
_______________________________________________ igraph-help mailing list [email protected] https://lists.nongnu.org/mailman/listinfo/igraph-help
