Package org.deeplearning4j.graph
Class Graph<V,E>
- java.lang.Object
-
- org.deeplearning4j.graph.api.BaseGraph<V,E>
-
- org.deeplearning4j.graph.Graph<V,E>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addEdge(Edge<E> edge)
Add an edge to the graph.boolean
equals(Object o)
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
hashCode()
int
numVertices()
Number of vertices in the graphString
toString()
-
-
-
Constructor Detail
-
Graph
public Graph(int numVertices, VertexFactory<V> vertexFactory)
-
Graph
public Graph(int numVertices, boolean allowMultipleEdges, VertexFactory<V> vertexFactory)
-
-
Method Detail
-
numVertices
public int numVertices()
Description copied from interface:IGraph
Number of vertices in the graph
-
getVertex
public Vertex<V> getVertex(int idx)
Description copied from interface:IGraph
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
public List<Vertex<V>> getVertices(int[] indexes)
Description copied from interface:IGraph
Get multiple vertices in the graph- Parameters:
indexes
- the indexes of the vertices to retrieve- Returns:
- list of vertices
-
getVertices
public List<Vertex<V>> getVertices(int from, int to)
Description copied from interface:IGraph
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
public void addEdge(Edge<E> edge)
Description copied from interface:IGraph
Add an edge to the graph.
-
getEdgesOut
public List<Edge<E>> getEdgesOut(int vertex)
Description copied from interface:IGraph
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
public int getVertexDegree(int vertex)
Description copied from interface:IGraph
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
public Vertex<V> getRandomConnectedVertex(int vertex, Random rng) throws NoEdgesException
Description copied from interface:IGraph
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
public List<Vertex<V>> getConnectedVertices(int vertex)
Description copied from interface:IGraph
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
public int[] getConnectedVertexIndices(int vertex)
Description copied from interface:IGraph
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:
IGraph.getConnectedVertices(int)
-
-