# Graph Tools

In dlib, there are two types of graph representations. On the one hand, there are graphs based on an object which encapsulates the whole graph, such as the graph and directed_graph objects. On the other hand, there are graphs which are represented as simple vectors of edges. In this case, we use vectors of sample_pair or ordered_sample_pair objects for undirected and directed graphs respectively.

Graph Object Based Graphs
graph_contains_directed_cycle
graph_has_symmetric_edges
graph_contains_undirected_cycle
create_moral_graph
triangulate_graph_and_find_cliques
graph_contains_length_one_cycle
find_connected_nodes
graph_is_connected
is_clique
is_maximal_clique
copy_graph_structure
copy_graph
edge
is_join_tree
create_join_tree
Edge List Based Graphs
sample_pair
ordered_sample_pair
find_percent_shortest_edges_randomly
find_k_nearest_neighbors
find_approximate_k_nearest_neighbors
remove_short_edges
remove_duplicate_edges
remove_long_edges
remove_percent_longest_edges
remove_percent_shortest_edges
squared_euclidean_distance
use_weights_of_one
use_gaussian_weights
is_ordered_by_index
find_neighbor_ranges
convert_unordered_to_ordered
sample_pair
dlib/graph_utils.h
dlib/graph_utils/sample_pair_abstract.h
This object is intended to represent an edge in an undirected graph which has data samples at its vertices. Therefore, it is the undirected version of ordered_sample_pair.
linear_manifold_regularizer_ex.cpp.html
ordered_sample_pair
dlib/graph_utils.h
dlib/graph_utils/ordered_sample_pair_abstract.h
This object is intended to represent an edge in a directed graph which has data samples at its vertices. Therefore, it is the directed version of sample_pair.
find_percent_shortest_edges_randomly
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This function is a simple approximate form of find_k_nearest_neighbors. Instead of checking all possible edges it randomly samples a large number of them and then returns the best ones.
linear_manifold_regularizer_ex.cpp.html
find_k_nearest_neighbors
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This is a function which finds all the k nearest neighbors of a set of points and outputs the result as a vector of sample_pair objects. It takes O(n^2) where n is the number of data samples. A faster approximate version is provided by find_approximate_k_nearest_neighbors.
find_approximate_k_nearest_neighbors
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This function is a simple approximate form of find_k_nearest_neighbors. Instead of checking all possible edges it randomly samples a large number of them and then performs exact k-nearest-neighbors on that randomly selected subset.
remove_short_edges
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This is a simple function for removing edges with a small distance value from a vector of sample_pair or ordered_sample_pair objects.
remove_duplicate_edges
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This is a simple function for removing duplicate edges (i.e. edges that compare equal according to ==) from a vector of sample_pair or ordered_sample_pair objects.
remove_long_edges
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This is a simple function for removing edges with a large distance value from a vector of sample_pair or ordered_sample_pair objects.
remove_percent_longest_edges
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This is a simple function for removing edges with a large distance value from a vector of sample_pair or ordered_sample_pair objects.
remove_percent_shortest_edges
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This is a simple function for removing edges with a small distance value from a vector of sample_pair or ordered_sample_pair objects.
squared_euclidean_distance
dlib/graph_utils.h
dlib/graph_utils/function_objects_abstract.h
This is a simple function object that computes squared euclidean distance between two matrix objects.
linear_manifold_regularizer_ex.cpp.html
use_weights_of_one
dlib/graph_utils.h
dlib/graph_utils/function_objects_abstract.h
This is a simple function object that takes a single argument and always returns 1
use_gaussian_weights
dlib/graph_utils.h
dlib/graph_utils/function_objects_abstract.h
This is a simple function object that takes a single argument which should be an object similar to sample_pair.
linear_manifold_regularizer_ex.cpp.html
is_ordered_by_index
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This function checks if a vector of sample_pair or ordered_sample_pair objects is in sorted order according to their index values.
find_neighbor_ranges
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This function takes a graph, defined by a vector of ordered_sample_pair objects, and finds the ranges that contain the edges for each node in the graph. The output therefore lets you easily locate the neighbors of any node in the graph.
convert_unordered_to_ordered
dlib/graph_utils.h
dlib/graph_utils/edge_list_graphs_abstract.h
This function takes a graph, defined by a vector of sample_pair objects and converts it into the equivalent graph defined by a vector of ordered_sample_pair objects.
edge
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph or directed_graph object and a pair of indices. It returns a reference to the edge object between the two nodes with the given indices.
is_join_tree
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes two graph objects and checks if the second of the two graphs is a valid join tree (aka tree decomposition) of the first graph.
create_join_tree
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph object and creates a join tree for that graph. Or in other words, this function finds a tree decomposition of the given graph.
graph_contains_directed_cycle
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function checks a directed_graph for directed cycles.
graph_has_symmetric_edges
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function checks if a directed_graph has a pair of nodes with just one edge between them. If so then it does not have symmetric edges.
triangulate_graph_and_find_cliques
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph and turns it into a chordal graph. It also returns a set that contains all the cliques present in the chordal graph.
create_moral_graph
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a directed_graph and returns the moralized version of the graph in the form of a graph object.
graph_contains_length_one_cycle
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph or directed_graph object and returns true if and only if the graph contains a node that has an edge that links back to itself.
find_connected_nodes
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a node from a graph or directed_graph object and a set of unsigned longs. It finds all the nodes in the given graph that are connected to the given node by an undirected path and returns them in the set (also note that the original query node is also returned in this set).
graph_is_connected
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph or directed_graph object and determines if the graph is connected. That is, it returns true if and only if there is an undirected path between any two nodes in the given graph.
is_clique
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph and a set of node index values and checks if the specified set of nodes is a clique in the graph.
copy_graph
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph or directed_graph and makes a copy of it.
copy_graph_structure
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph or directed_graph and copies its structure to another graph or directed_graph object. The only restriction is that you can't copy the structure of a graph into a directed_graph. The three other possible combinations are allowed however.
is_maximal_clique
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function takes a graph and a set of node index values and checks if the specified set of nodes is a maximal clique in the graph.
graph_contains_undirected_cycle
dlib/graph_utils.h
dlib/graph_utils/graph_utils_abstract.h
This function checks a directed_graph for undirected cycles.