Discussion Forum

Random walks from graph data?

Hello grakn community,

I have a project idea where I would need random walk samples of graph data and I am currently trying to look for graph database systems where this can be easily implemented.

A random walk sample should start somewhere in the graph network and travel from there a defined step-length from node to node randomly choosing the path.

Is there an easy way to implement this with grakn?

Kind regards

Hi Michael,

Random walks are quite easy to implement with Grakn using the ConceptAPI. One possible method has pseudocode like this:

Start at a Thing that you want to walk from, query for that thing so that you have a concept for it in your application. Let’s say that concept has local variable name thing

Randomly pick whether you want to walk to :
(1) a relation (if the current thing plays a role),
(2) a roleplayer (if you’re currently at a relation),
(3) an attribute,
(4) owners (if you’re at an attribute)

Now we have a kind of connection that we’re looking for as the next step in the walk, so make a call to the concept API to get the relevant neighbours, either:
(1) thing.relations(),
(2) thing.rolePlayersMap(),
(3) thing.attributes(),
(4) thing.owners()

From the list of neighbours you now have, randomly pick one as the next step in the walk.

Repeat the process on this neighbour to find the next step.

I hope this helps!