[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] sample graph via random walk
From: |
Tamás Nepusz |
Subject: |
Re: [igraph] sample graph via random walk |
Date: |
Thu, 10 Jul 2014 21:02:52 +0200 |
No, there isn't, as far as I know. If you are using igraph from Python, here's
a quick implementation of a random walk iterator:
import random
def random_walk(g, start=None):
current = random.randint(0, g.vcount()-1) if start is None else start
stop = False
while not stop:
stop = yield current
current = random.choice(g.successors(current))
You can then combine this with itertools.islice() to get a random walk with a
given length:
vs = list(islice(random_walk(g, start=5), desired_length))
and then you can take the subgraph:
g2 = g.induced_subgraph(vs)
But the iterator also lets you stop the random walk when you reach a given
vertex if you combine it with itertools.takewhile() instead:
destination = 20
vs = list(takewhile(lambda x: x != destination, random_walk(g, start=5))) +
[destination]
--
T.
------------------------------------------------------
From: Николай Кинаш address@hidden
Reply: Help for igraph users address@hidden
Date: 10 July 2014 at 05:33:47
To:address@hidden address@hidden
Subject: [igraph] sample graph via random walk
> Hi all.
>
> Is there a built-in function to get subgraph from random walk on graph?
>
> Thanks.
> _______________________________________________
> igraph-help mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/igraph-help
>