liveBook · Manning

Second-order biased random walk

As explained in Graph Algorithms for Data Science

A second-order random walk is a graph walk whose next traversal probabilities depend on both the current node and the node visited immediately before it.

A second-order biased random walk chooses its next node using both the current node and the node visited immediately before it. This contrasts with a first-order walk, which considers only its current node. section 9.3.2

The technique is used by node2vec to generate node sequences. Each sequence treats visited nodes as words, and the resulting sentences become training examples for the word2vec skip-gram model. Walk length controls sentence size, and walks begin from every node to capture the graph broadly. section 9.3.2 section 9.5

Key implementation ideas include:

  • Use the previous step when evaluating the next traversal, rather than treating every visit to the current node identically. section 9.3.2
  • Account for relationship weights when the graph is weighted; a connection's probability reflects its weight relative to neighboring weights. section 9.3.2
  • Adjust walk length to control how many nodes appear in each generated sentence. section 9.3.2

Choosing the next move

After a walk moves from node D to node A, the next traversal is evaluated with both A and D in context. A first-order walk would use only A, assigning equal probabilities to four unweighted neighbors. section 9.3.2

Figure 9.13 Second-order random walks
09-13

Use the graph illustration to trace how the immediately previous node changes the next traversal possibilities. section 9.3.2

How Graph Algorithms for Data Science covers it

How deep it goes
Explains first-order contrast, previous-state dependence, weights, and walk length, but does not provide the full probability formula.
Examples
Uses graph figures with nodes A, C, B, F, D, and E plus weighted traversal examples to illustrate walk behavior.
What it assumes
Assumes basic graph navigation and introduces first-order versus second-order traversal behavior without advanced mathematics.
What you can do after
Apply it via node2vec by tuning walk length and interpreting generated node sequences as embedding-training data.
How it connects
Connects random walks to node2vec, word2vec skip-gram, node embeddings, homophily, and structural roles.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.