org.deeplearning4j.graph.iterator

## Class RandomWalkIterator<V>

• All Implemented Interfaces:
GraphWalkIterator<V>

```public class RandomWalkIterator<V>
extends Object
implements GraphWalkIterator<V>```
Given a graph, iterate through random walks on that graph of a specified length. Random walks are generated starting at every node in the graph exactly once, though the order of the starting nodes is randomized.
Author:
Alex Black
• ### Constructor Summary

Constructors
Constructor and Description
```RandomWalkIterator(IGraph<V,?> graph, int walkLength)```
```RandomWalkIterator(IGraph<V,?> graph, int walkLength, long rngSeed)```
Construct a RandomWalkIterator for a given graph, with a specified walk length and random number generator seed.
```RandomWalkIterator(IGraph<V,?> graph, int walkLength, long rngSeed, NoEdgeHandling mode)```
```RandomWalkIterator(IGraph<V,?> graph, int walkLength, long rngSeed, NoEdgeHandling mode, int firstVertex, int lastVertex)```
Constructor used to generate random walks starting at a subset of the vertices in the graph.
• ### Method Summary

All Methods
Modifier and Type Method and Description
`boolean` `hasNext()`
Whether the iterator has any more vertex sequences.
`IVertexSequence<V>` `next()`
Get the next vertex sequence.
`void` `reset()`
Reset the graph walk iterator.
`int` `walkLength()`
Length of the walks returned by next() Note that a walk of length `i` contains `i+1` vertices
• ### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`
• ### Constructor Detail

• #### RandomWalkIterator

```public RandomWalkIterator(IGraph<V,?> graph,
int walkLength)```
• #### RandomWalkIterator

```public RandomWalkIterator(IGraph<V,?> graph,
int walkLength,
long rngSeed)```
Construct a RandomWalkIterator for a given graph, with a specified walk length and random number generator seed.
Uses `NoEdgeHandling.EXCEPTION_ON_DISCONNECTED` - hence exception will be thrown when generating random walks on graphs with vertices containing having no edges, or no outgoing edges (for directed graphs)
`RandomWalkIterator(IGraph, int, long, NoEdgeHandling)`
• #### RandomWalkIterator

```public RandomWalkIterator(IGraph<V,?> graph,
int walkLength,
long rngSeed,
NoEdgeHandling mode)```
Parameters:
`graph` - IGraph to conduct walks on
`walkLength` - length of each walk. Walk of length 0 includes 1 vertex, walk of 1 includes 2 vertices etc
`rngSeed` - seed for randomization
`mode` - mode for handling random walks from vertices with either no edges, or no outgoing edges (for directed graphs)
• #### RandomWalkIterator

```public RandomWalkIterator(IGraph<V,?> graph,
int walkLength,
long rngSeed,
NoEdgeHandling mode,
int firstVertex,
int lastVertex)```
Constructor used to generate random walks starting at a subset of the vertices in the graph. Order of starting vertices is randomized within this subset
Parameters:
`graph` - IGraph to conduct walks on
`walkLength` - length of each walk. Walk of length 0 includes 1 vertex, walk of 1 includes 2 vertices etc
`rngSeed` - seed for randomization
`mode` - mode for handling random walks from vertices with either no edges, or no outgoing edges (for directed graphs)
`firstVertex` - first vertex index (inclusive) to start random walks from
`lastVertex` - last vertex index (exclusive) to start random walks from
• ### Method Detail

• #### next

`public IVertexSequence<V> next()`
Description copied from interface: `GraphWalkIterator`
Get the next vertex sequence.
Specified by:
`next` in interface `GraphWalkIterator<V>`
• #### hasNext

`public boolean hasNext()`
Description copied from interface: `GraphWalkIterator`
Whether the iterator has any more vertex sequences.
Specified by:
`hasNext` in interface `GraphWalkIterator<V>`
• #### reset

`public void reset()`
Description copied from interface: `GraphWalkIterator`
Reset the graph walk iterator.
Specified by:
`reset` in interface `GraphWalkIterator<V>`
• #### walkLength

`public int walkLength()`
Description copied from interface: `GraphWalkIterator`
Length of the walks returned by next() Note that a walk of length `i` contains `i+1` vertices
Specified by:
`walkLength` in interface `GraphWalkIterator<V>`