Package org.deeplearning4j.graph.api
Interface IGraph<V,E>
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addEdge(int from, int to, E value, boolean directed)
Convenience method for adding an edge (directed or undirected) to graphvoid
addEdge(Edge<E> edge)
Add an edge to the graph.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) existsList<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) existsList<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 edgesVertex<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 indexint
getVertexDegree(int vertex)
Returns the degree of the vertex.
For undirected graphs, this is just the degree.
For directed graphs, this returns the outdegreeList<Vertex<V>>
getVertices(int[] indexes)
Get multiple vertices in the graphList<Vertex<V>>
getVertices(int from, int to)
Get multiple vertices in the graph, with secified indicesint
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, inclusiveto
- last vertex to get, inclusive- Returns:
- list of vertices
-
addEdge
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 fromrng
- 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
- See Also:
getConnectedVertices(int)
-
-