org.deeplearning4j.models.sequencevectors.graph.primitives

## Interface IGraph<V extends SequenceElement,E extends Number>

• Type Parameters:
`V` - type for vertex objects
`E` - type for edge objects
All Known Implementing Classes:
Graph

`public interface IGraph<V extends SequenceElement,E extends Number>`
Interface for a IGraph, with objects for each vertex and edge. In the simplest case, edges and vertices may be labelled (i.e., IGraph for example), or may be any arbitrary object (or, null).
IGraph may include directed edges, undirected edges, or a combination of both
Note: Every vertex in the graph has an integer index, in range of 0 to numVertices() inclusive
Author:
Alex Black
• ### Method Summary

All Methods
Modifier and Type Method and Description
`void` `addEdge(Edge<E> edge)`
Add an edge to the graph.
`void` ```addEdge(int from, int to, E value, boolean directed)```
Convenience method for adding an edge (directed or undirected) to graph
`int[]` `getConnectedVertexIndices(int vertex)`
Return an array of indexes of vertices that the specified vertex is connected to.
`List<Vertex<V>>` `getConnectedVertices(int vertex)`
Get a list of all of the vertices that the specified vertex is connected to
Specifically, for undirected graphs return list of all X such that (vertex -- X) exists
For directed graphs, return list of all X such that (vertex -> X) exists
`List<Edge<E>>` `getEdgesOut(int vertex)`
Returns a list of edges for a vertex with a given index For undirected graphs, returns all edges incident on the vertex For directed graphs, only returns outward directed edges
`Vertex<V>` ```getRandomConnectedVertex(int vertex, Random rng)```
Randomly sample a vertex connected to a given vertex.
`Vertex<V>` `getVertex(int idx)`
Get a vertex in the graph for a given index
`int` `getVertexDegree(int vertex)`
Returns the degree of the vertex.
`List<Vertex<V>>` `getVertices(int[] indexes)`
Get multiple vertices in the graph
`List<Vertex<V>>` ```getVertices(int from, int to)```
Get multiple vertices in the graph, with secified indices
`int` `numVertices()`
Number of vertices in the graph
• ### Method Detail

• #### numVertices

`int numVertices()`
Number of vertices in the graph
• #### getVertex

`Vertex<V> getVertex(int idx)`
Get a vertex in the graph for a given index
Parameters:
`idx` - integer index of the vertex to get. must be in range 0 to numVertices()
Returns:
vertex
• #### getVertices

`List<Vertex<V>> getVertices(int[] indexes)`
Get multiple vertices in the graph
Parameters:
`indexes` - the indexes of the vertices to retrieve
Returns:
list of vertices
• #### getVertices

```List<Vertex<V>> getVertices(int from,
int to)```
Get multiple vertices in the graph, with secified indices
Parameters:
`from` - first vertex to get, inclusive
`to` - last vertex to get, inclusive
Returns:
list of vertices

`void addEdge(Edge<E> edge)`
Add an edge to the graph.

```void addEdge(int from,
int to,
E value,
boolean directed)```
Convenience method for adding an edge (directed or undirected) to graph
• #### getEdgesOut

`List<Edge<E>> getEdgesOut(int vertex)`
Returns a list of edges for a vertex with a given index For undirected graphs, returns all edges incident on the vertex For directed graphs, only returns outward directed edges
Parameters:
`vertex` - index of the vertex to
Returns:
list of edges for this vertex
• #### getVertexDegree

`int getVertexDegree(int vertex)`
Returns the degree of the vertex.
For undirected graphs, this is just the degree.
For directed graphs, this returns the outdegree
Parameters:
`vertex` - vertex to get degree for
Returns:
vertex degree
• #### getRandomConnectedVertex

```Vertex<V> getRandomConnectedVertex(int vertex,
Random rng)
throws NoEdgesException```
Randomly sample a vertex connected to a given vertex. Sampling is done uniformly at random. Specifically, returns a random X such that either a directed edge (vertex -> X) exists, or an undirected edge (vertex -- X) exists
Can be used for example to implement a random walk on the graph (specifically: a unweighted random walk)
Parameters:
`vertex` - vertex to randomly sample from
`rng` - Random number generator to use
Returns:
A vertex connected to the specified vertex,
Throws:
`NoEdgesException` - thrown if the specified vertex has no edges, or no outgoing edges (in the case of a directed graph).
• #### getConnectedVertices

`List<Vertex<V>> getConnectedVertices(int vertex)`
Get a list of all of the vertices that the specified vertex is connected to
Specifically, for undirected graphs return list of all X such that (vertex -- X) exists
For directed graphs, return list of all X such that (vertex -> X) exists
Parameters:
`vertex` - Index of the vertex
Returns:
list of vertices that the specified vertex is connected to
• #### getConnectedVertexIndices

`int[] getConnectedVertexIndices(int vertex)`
Return an array of indexes of vertices that the specified vertex is connected to.
Specifically, for undirected graphs return int[] of all X.vertexID() such that (vertex -- X) exists
For directed graphs, return int[] of all X.vertexID() such that (vertex -> X) exists
Parameters:
`vertex` - index of the vertex
Returns:
list of vertices that the specified vertex is connected to
`getConnectedVertices(int)`