T
- The class of the node, used when getting a nodepublic class Graph<T> extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_K
Number of edges per node.
|
static double |
DEFAULT_SEARCH_EXPANSION
Fast search: expansion parameter.
|
static int |
DEFAULT_SEARCH_RANDOM_JUMPS
Fast search: number of random jumps per node (to simulate small world
graph).
|
static double |
DEFAULT_SEARCH_SPEEDUP
Fast search: speedup compared to exhaustive search.
|
static int |
DEFAULT_UPDATE_DEPTH
Fast add or remove node: depth of search to update the graph.
|
Constructor and Description |
---|
Graph()
Initialize an empty graph with k = 10.
|
Graph(Graph<T> origin)
Copy constructor.
|
Graph(int k)
Initialize an empty graph, and set k (number of edges per node).
|
Modifier and Type | Method and Description |
---|---|
int |
add(T new_node)
Add a node to the online graph using exhaustive search approach.
|
int |
compare(Graph<T> other)
Count the number of edges/neighbors that are the same (based on
similarity) in both graphs.
|
ArrayList<Graph<T>> |
connectedComponents()
Split the graph in connected components (usually you will first prune the
graph to remove "weak" edges).
|
boolean |
containsKey(T node) |
Iterable<Map.Entry<T,NeighborList>> |
entrySet() |
boolean |
equals(Object obj) |
void |
fastAdd(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.
|
void |
fastAdd(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.
|
void |
fastAdd(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.
|
void |
fastAdd(T new_node,
double speedup,
int long_jumps,
double expansion,
int update_depth,
StatisticsContainer stats)
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.
|
void |
fastRemove(T node_to_remove)
Remove a node from the graph (and update the graph) using fast
approximate algorithm.
|
void |
fastRemove(T node_to_remove,
int update_depth,
StatisticsContainer stats)
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.
|
NeighborList |
fastSearch(T query,
int k,
double speedup,
int long_jumps,
double expansion,
StatisticsContainer stats)
Approximate fast graph based search, as published in "Fast Online k-nn
Graph Building" by Debatty et al.
|
LinkedList<T> |
findNeighbors(LinkedList<T> starting_points,
int depth)
Recursively search neighbors of neighbors, up to a given depth.
|
T |
first()
Get the first node in the graph.
|
HashMap<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).
|
NeighborList |
getNeighbors(T node)
Get the neighborlist of this node.
|
Iterable<T> |
getNodes() |
SimilarityInterface<T> |
getSimilarity()
Get the similarity measure.
|
int |
hashCode() |
void |
prune(double threshold)
Remove from the graph all edges with a similarity lower than threshold.
|
NeighborList |
put(T node,
NeighborList neighborlist) |
NeighborList |
search(T query,
int k)
Multi-thread exhaustive search.
|
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.
|
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).
|
String |
toString() |
void |
writeGEXF(String filename)
Writes the graph as a GEXF file (to be used in Gephi, for example).
|
public static final int DEFAULT_K
public static final double DEFAULT_SEARCH_SPEEDUP
public static final double DEFAULT_SEARCH_EXPANSION
public static final int DEFAULT_SEARCH_RANDOM_JUMPS
public static final int DEFAULT_UPDATE_DEPTH
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 getNeighbors(T node)
node
- public final 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(T node, NeighborList neighborlist)
node
- neighborlist
- public final boolean containsKey(T node)
node
- public final int size()
public final Iterable<Map.Entry<T,NeighborList>> entrySet()
public final LinkedList<T> findNeighbors(LinkedList<T> starting_points, int depth)
starting_points
- depth
- public final HashMap<T,NeighborList> getHashMap()
public final NeighborList search(T query, int k) throws InterruptedException, ExecutionException
query
- k
- InterruptedException
- if thread is interruptedExecutionException
- if thread cannot completepublic 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
- k
- speedup
- long_jumps
- expansion
- public final NeighborList fastSearch(T query, int k, double speedup, int long_jumps, double expansion, StatisticsContainer stats)
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)stats
- public final void writeGEXF(String filename) throws FileNotFoundException, IOException
filename
- FileNotFoundException
- if filename is invalidIOException
- if cannot write to filepublic final int add(T new_node)
new_node
- public final void fastAdd(T node)
node
- public final void fastAdd(T node, double speedup)
node
- speedup
- public final void fastAdd(T new_node, double speedup, int long_jumps, double expansion)
new_node
- speedup
- compared to exhaustive searchlong_jumps
- expansion
- public final void fastAdd(T new_node, double speedup, int long_jumps, double expansion, int update_depth, StatisticsContainer stats)
new_node
- speedup
- compared to exhaustive searchlong_jumps
- expansion
- update_depth
- stats
- public final void fastRemove(T node_to_remove)
node_to_remove
- public final void fastRemove(T node_to_remove, int update_depth, StatisticsContainer stats)
node_to_remove
- update_depth
- stats
- public final int compare(Graph<T> other)
other
- Copyright © 2017. All rights reserved.