[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
## Re: [igraph] select node with probability proportional to degree

**From**: |
Simone Gabbriellini |

**Subject**: |
Re: [igraph] select node with probability proportional to degree |

**Date**: |
Tue, 22 Mar 2011 10:09:33 +0100 |

many thanks Tamas!
simone
Il giorno 21/mar/2011, alle ore 23.38, Tamás Nepusz ha scritto:
>*> I would like to select nodes in my network with a probability proportional *
>*> to a node's attribute or structural properties, i.e. degree. *
>*> Any hint on the python best way to accomplish this task is more than welcome.*
>* 1. Take the cumulative sum of the degrees (i.e. calculate a list where *
>* element i is the sum of the elements in the original list from index 0 to *
>* index i, inclusive).*
>* *
>* 2. Generate a random integer between 0 and the last element of the cumulative *
>* sum list (which is also the largest btw).*
>* *
>* 3. Using binary search (see the bisect module), find the index in the *
>* cumulative sum list where the generated random number should be inserted to *
>* keep the list sorted. This index is the index of the node you are looking for.*
>* *
>* -- *
>* T.*
>* *
>* *
>* _______________________________________________*
>* igraph-help mailing list*
>* address@hidden*
>* http://lists.nongnu.org/mailman/listinfo/igraph-help*