T
- The type of nodes valuepublic class Graph<T> extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
static double |
DEFAULT_EXPANSION |
static int |
DEFAULT_K |
static int |
DEFAULT_LONG_JUMPGS |
static double |
DEFAULT_SEARCH_SPEEDUP |
static int |
DEFAULT_UPDATE_DEPTH |
Constructor and Description |
---|
Graph()
Initialize an empty graph with k = 10.
|
Graph(int k)
Initialize an empty graph, and set k (number of edges per node).
|
Modifier and Type | Method and Description |
---|---|
int |
add(Node<T> new_node)
Add a node to the online graph using exhaustive search approach.
|
ArrayList<Graph<T>> |
connectedComponents()
Split the graph in connected components (usually you will first prune the
graph to remove "weak" edges).
|
boolean |
containsKey(Node node) |
Iterable<Map.Entry<Node<T>,NeighborList>> |
entrySet() |
int |
fastAdd(Node<T> node)
Add a node to the online graph, using approximate online graph building
algorithm presented in "Fast Online k-nn Graph Building" by Debatty
et al.
|
int |
fastAdd(Node<T> node,
double speedup)
Add a node to the online graph, using approximate online graph building
algorithm presented in "Fast Online k-nn Graph Building" by Debatty
et al.
|
int |
fastAdd(Node<T> new_node,
double speedup,
int long_jumps,
double expansion)
Add a node to the online graph, using approximate online graph building
algorithm presented in "Fast Online k-nn Graph Building" by Debatty
et al.
|
int |
fastRemove(Node<T> node_to_remove)
Remove a node from the graph (and update the graph) using fast
approximate algorithm.
|
NeighborList |
fastSearch(T query,
int k)
Approximate fast graph based search, as published in "Fast Online k-nn
Graph Building" by Debatty et al.
|
NeighborList |
fastSearch(T query,
int k,
double speedup)
Approximate fast graph based search, as published in "Fast Online k-nn
Graph Building" by Debatty et al.
|
NeighborList |
fastSearch(T query,
int k,
double speedup,
int long_jumps,
double expansion)
Approximate fast graph based search, as published in "Fast Online k-nn
Graph Building" by Debatty et al.
|
LinkedList<Node<T>> |
findNeighbors(LinkedList<Node<T>> starting_points,
int depth)
Recursively search neighbors of neighbors, up to a given depth.
|
Node<T> |
first()
Get the first node in the graph.
|
NeighborList |
get(Node node)
Get the neighborlist of this node.
|
HashMap<Node<T>,NeighborList> |
getHashMap()
Get the underlying hash map that stores the nodes and associated
neighborlists.
|
int |
getK()
Get k (the number of edges per node).
|
Iterable<Node<T>> |
getNodes() |
SimilarityInterface<T> |
getSimilarity()
Get the similarity measure.
|
void |
prune(double threshold)
Remove from the graph all edges with a similarity lower than threshold.
|
NeighborList |
put(Node<T> node,
NeighborList neighborlist) |
NeighborList |
searchExhaustive(T query,
int k)
Multi-thread exhaustive search.
|
void |
setDepth(int update_depth)
Modify the depth for updating existing edges (default is 2).
|
void |
setK(int k)
Set k (the number of edges per node).
|
void |
setSimilarity(SimilarityInterface<T> similarity)
Set the similarity measure used to build or search the graph.
|
void |
setWindowSize(int window_size)
Set the size of the window (number of nodes to keep in the graph).
|
int |
size() |
ArrayList<Graph<T>> |
stronglyConnectedComponents()
Computes the strongly connected sub-graphs (where every node is reachable
from every other node) using Tarjan's algorithm, which has computation
cost O(n).
|
void |
writeGEXF(String filename)
Writes the graph as a GEXF file (to be used in Gephi, for example).
|
public static final double DEFAULT_EXPANSION
public static final int DEFAULT_K
public static final int DEFAULT_UPDATE_DEPTH
public static final double DEFAULT_SEARCH_SPEEDUP
public static final int DEFAULT_LONG_JUMPGS
public Graph(int k)
k
- public Graph()
public final SimilarityInterface<T> getSimilarity()
public final void setSimilarity(SimilarityInterface<T> similarity)
similarity
- public final int getK()
public final void setK(int k)
k
- public final NeighborList get(Node node)
node
- public final Node<T> first() throws NoSuchElementException
NoSuchElementException
- if the graph is empty...public final void prune(double threshold)
threshold
- public final ArrayList<Graph<T>> connectedComponents()
public final ArrayList<Graph<T>> stronglyConnectedComponents()
public final NeighborList put(Node<T> node, NeighborList neighborlist)
node
- neighborlist
- public final boolean containsKey(Node node)
node
- public final int size()
public final Iterable<Map.Entry<Node<T>,NeighborList>> entrySet()
public final LinkedList<Node<T>> findNeighbors(LinkedList<Node<T>> starting_points, int depth)
starting_points
- depth
- public final HashMap<Node<T>,NeighborList> getHashMap()
public final NeighborList searchExhaustive(T query, int k) throws InterruptedException, ExecutionException
query
- k
- InterruptedException
ExecutionException
public final NeighborList fastSearch(T query, int k)
query
- k
- search K neighborspublic final NeighborList fastSearch(T query, int k, double speedup)
query
- k
- search k neighborsspeedup
- speedup for searching (> 1, default 4)public final NeighborList fastSearch(T query, int k, double speedup, int long_jumps, double expansion)
query
- query pointk
- number of neighbors to find (the K from K-nn search)speedup
- (default: 4.0)long_jumps
- (default: 2)expansion
- (default: 1.2)public final void writeGEXF(String filename) throws FileNotFoundException, IOException
filename
- FileNotFoundException
- if filename is invalidIOException
- if cannot write to filepublic final void setDepth(int update_depth)
update_depth
- public final void setWindowSize(int window_size)
window_size
- public final int add(Node<T> new_node)
new_node
- public final int fastAdd(Node<T> node)
node
- public final int fastAdd(Node<T> node, double speedup)
node
- speedup
- public final int fastAdd(Node<T> new_node, double speedup, int long_jumps, double expansion)
new_node
- speedup
- compared to exhaustive searchlong_jumps
- expansion
- Copyright © 2016. All rights reserved.